php - Extract block of consecutive alphanumeric characters from a line of text -


imagine have list of products, such as:

  • branded hgt15k51b item words describe it
  • named cdgl-56 product description
  • fancy item tr64gqe350 added gizmo
  • another branded 106110 110cm sized green item fan

i trying extract product code only.

this large block of consecutive text. may contain a-z 1-9 _ -. it's uppercase. end space. has unknown length. may numeric only. it's largest consecutive block in string.

my regex skills weak, possible extract regex? there better way?

thanks

you can try

(?<!\s)[a-z0-9-]{5,}(?!\s)

https://regex101.com/r/zhe8nc/2

 (?<! \s )        # whitespace boundary  [a-z0-9-]{5,}    # allowed characters, minimum 5  (?! \s )         # whitespace boundary 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -