Help with regex to find part numbers!

Hi All,

I have the following case insensitive pattern:
[a-z0-9-.,/]{4,}(?<=\d)

What this does is tries to find part numbers (collections of letters, dashes, the period etc) that contains at least one number. It works well enough until I came to this string where its only finding a partial match.

Glove Valve 5K-15A   asdasd

I would expect it to pull the 5K-15A but it only takes the 5K-15.

Can someone suggest how to tweak to fix this?
LVL 11
SlimshaneeyAsked:
Who is Participating?
 
käµfm³d 👽Commented:
Well your lookbehind, as I mentioned, ensures that the last character is a digit. If you want to ensure that there is at least one digit, then you could do:

(?i)(?=[a-z-.,/]*\d)[a-z0-9-.,/]{4,}

Open in new window

0
 
SlimshaneeyAuthor Commented:
I think I have solved my own problem here. If anyone can see a flaw in this do let me know though:

\b[a-z0-9-./]{4,}(?<=\d)[a-z0-9-./]{0,}\b
0
 
käµfm³d 👽Commented:
You have a positive lookbehind [ (?<= ... ) ] in your patter which expects a digit to be the last character. Why not simply remove that?

[a-z0-9-.,/]{4,}

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
SlimshaneeyAuthor Commented:
If I removed that it would match words that dont contain a digit, which isnt what I want, Im looking got anything with at least one number in it.
0
 
SlimshaneeyAuthor Commented:
That works very nicely, what does the initial (?i) do?
0
 
käµfm³d 👽Commented:
You probably don't need it (because I think you mentioned it in your OP), but it enables case-insensitive matching. I just copy/pasted from my tester application (Expresso), and I had it in there to recreate your case-insensitivity.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.