Reputation: 2147
I need to configure an app that takes a regex as a parameter. It is a .NET application, and uses the default .NET regex engine.
In the app, there is a string that looks either like this:
blah blah blah 123-123PQ
or this:
blah blah blah 456456ZR
I need the 123123 or the 465456 without the rest of the string, in a single named capture group
I have gotten this far:
(\b(?<number>\d+(?:-\d*)?)PQ|(?<number>\d+(?:\d*)?)ZR\b)
This captures either the first set of numbers or the second, but in the first format the result still has the "-" character in it.
My question: How do I do a backreference and grab only the numeric portion from the capture group?
Upvotes: 0
Views: 48
Reputation: 12427
I do not think this is possible - here's a question that seems to be exactly the same thing you're asking for:
Regex Pattern Matching Concatenation
Upvotes: 2