What for? Debugging?
you can include code behind each group, which is only executed if the former matched.
DB<7> p 'okoK'=~ /(o|k)(?{print "#1 matched"})(k|i)(O|K)(K)/
#1 matched
this can become extremely ugly with more complex regexes
And this is no sure bet, Perl can skip the attempt to match, if heuristics tell that there is no chance to ever succeed.
DB<12> p 'okoK'=~ /(o|k)(?{print "#1 matched"})(k|i)X(O|K)(K)/ #
+ no "X", why bother?
DB<13>
So you have to play around with use re "debug" and friends to find the real reason - see re - or use an interactive regex debugger.
Both require understanding how regexes work internally.
|