in reply to Regex: return the pattern instead of the actual match
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: return the pattern instead of the actual match
by Deus Ex (Scribe) on Sep 16, 2011 at 06:10 UTC |