[SOLVED] RegEx - Anyone know how to do this?

BrianDrab

Emeritus
Joined
Oct 20, 2014
Posts
18,133
Location
United States
I'm not very good at RegEx. I know the basics but have run into a need. Any idea how to write a RegEx that will always extract the parts in Red? Treat each line below as a separate record.

These are notes in a comment field. It will have text and numbers 38888837773 and also a combination of them like 01-645
Sometimes it will be in the middle like 17-1790. There is always a dash between the numbers that we want.
We can have scenarios where there are numbers followed by a space followed by what we want like 3838373737833893 27-378
51-201 and sometimes the number will be right at the beginning like this.
38373737337 37-298 or like this.
51-072 3938383838 or like this.

Any help would be extremely appreciated. Thank you.
 
If the first 2 digits is always a length of 2 and you want to ensure that you have digits after the '-' you should change it to this:
Code:
[plain]\d{2}-\d+[/plain]

\d* can match 0 or more digits so that may not be entirely suitable.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top