I have a list of regular expressions (about 10 - 15) that I needed to match against some text. Matching them one by one in a loop is too slow. But instead of writing up my own state machine to match all the regexes at once, I am trying to |
the individual regexes and let perl do the work. The problem is that how do I know which of the alternatives matched?
This question addresses the case where there are no capturing groups inside each individual regex. (which portion is matched by regex?) What if there are capturing groups inside each regexes?
So with the following,
/^(A(\d+))|(B(\d+))|(C(\d+))$/
and the string "A123", how can I both know that A123 matched and extract "123"?