What's new

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

BrianDrab

Administrator, Windows Update Instructor, Security Analyst
Staff member
Joined
Oct 20, 2014
Messages
17,750
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.
 

Tekno Venus

Senior Administrator, Site Designer
Staff member
Joined
Jul 21, 2012
Messages
6,067
Location
UK
Will this work for you?

Code:
(\d)*-(\d)*
 

BrianDrab

Administrator, Windows Update Instructor, Security Analyst
Staff member
Joined
Oct 20, 2014
Messages
17,750
It works perfectly!!!! Thank you so much.
 

AceInfinity

Moderator, Programming, Contributor
Joined
Feb 21, 2012
Messages
1,729
Location
Canada
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:
\d{2}-\d+
\d* can match 0 or more digits so that may not be entirely suitable.
 
Top