Reputation: 8341
I am trying to find/match the number sequences in bold in the example lines below using regular expressions.
2520222 Rubble,Barney 1134525
1524356 Mudd,Harry S 14-40525 111.11
2324316 Mudd,Mary R 12-40000
The closest that I've come is
\d{0,2}-?\d+$
But that only works when the section I want to capture is at the end of the line because of the $. If there is an unwanted item at the end of the line (see line #3) it will always be a decimal. Is there a way find that and step back one group to the correct sequence? Is it even possible in RegEx?
Upvotes: 2
Views: 43
Reputation: 30995
You can use look arounds in a regex like this:
(?<= )[\d-]+(?=\s|$)
If you don't want to use lookarounds, then you could use a regex like this:
,.*\s([\d-]+)(?:$|\s)
Upvotes: 5