I have a regular expression to match 2 different number formats: \=(?[0-9]+)\?|\+(?[0-9]+)\?
This should return 9876543 as its Value for ;1234567890123456?+1234567890123456789012345123=9876543?
and ;1234567890123456?+9876543? What I would like is to be able to return another value along with the matched ‘Value’.
So, for example, if the first string was matched, I’d like it to return:
Value: 9876543 Format: LongFormat
And if matched in the second string:
Value: 9876543 Format: ShortFormat
Is this possible?
Another option, which is not quite the solution you wanted, but saves you using two separate regexes, is to use named groups, if your implementation supports it.
Here is some C#:
Basically just modify your regex to include the names, and then regex.Groups[GroupName] will either have a value or wont. You could even just use the Success property of the group to know which matched (match.Groups[‘Long’].Success).
UPDATE: You can get the group name out of the match, with the following code:
I’m ignoring the 0th group, because that is always the entire match in .NET