Perhaps you are trying to see which of the two alternations matched. I wonder if this would be close enough.
$ perl -E ' > $rx = qr{(?x) > ( > foo\d+(?{say q{matched foo\d+}}) > | > bar\S+?(?{say qq{matched bar\S+?}}) > ) > }; > q{abcfoo44fred} =~ $rx && say qq{captured $1}; > q{barbell} =~ $rx && say qq{captured $1}; > q{xyz} =~ $rx && say qq{captured $1};' matched foo\d+ captured foo44 matched bar\S+? captured barb $
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Regex: return the pattern instead of the actual match
by johngg
in thread Regex: return the pattern instead of the actual match
by Deus Ex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |