?
Solved

Help with regex to find part numbers!

Posted on 2012-08-17
6
Medium Priority
?
822 Views
Last Modified: 2012-08-17
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?
0
Comment
Question by:Slimshaneey
  • 3
  • 3
6 Comments
 
LVL 11

Author Comment

by:Slimshaneey
ID: 38304292
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38304311
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
 
LVL 11

Author Comment

by:Slimshaneey
ID: 38304318
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38304351
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
 
LVL 11

Author Comment

by:Slimshaneey
ID: 38304354
That works very nicely, what does the initial (?i) do?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38304364
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
The viewer will learn how to dynamically set the form action using jQuery.
Simple Linear Regression
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question