my (@matches) = ($line =~ $re) if (defined $&) { $cb->(@matches); last; }
nope, the real problem is that @matches = (1) if it matched without capture groups in $re
new attempt:
if ( my (@caps) = ($line =~ $re) ) { @caps = () if $caps[0] ne $1; # reset pseudo capture +s $cb->(@caps); last; }
Full backwards compatible and no performance penalty.
OK?
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
In reply to Re^4: How to know that a regexp matched, and get its capture groups?
by LanX
in thread How to know that a regexp matched, and get its capture groups?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |