in reply to Re^3: How to know that a regexp matched, and get its capture groups?
in thread How to know that a regexp matched, and get its capture groups?
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: How to know that a regexp matched, and get its capture groups?
by AnomalousMonk (Archbishop) on Jan 11, 2023 at 06:22 UTC | |
by haukex (Archbishop) on Jan 11, 2023 at 09:27 UTC | |
by LanX (Saint) on Jan 11, 2023 at 11:30 UTC |