I need help with a regex to capture the numbers and hyphen from the following string:
“some text and stuff 200-1234EM some other stuff”
It can also appear without the hypenated part:
“some text 123EM other text”
I need either “200-1234” or “123” in a named capture group.
I tried this:
\b([0-9]{0,3}\-{0,1}[0-9]{3})EM\b
It does match, but it is not a named group.
When I try to name the group like this:
\b(?<test>[0-9]{0,3}\-{0,1}[0-9]{3})EM\b I get an error message “Unknown look-behind group near index 34”
I need this to work in the .NET RegEx class
Thanks!
This should do the trick. If you provide more input I could make it more robust.
Explanation: