in reply to Regex Subexpressions
my @regexps = ( qr/a/, qr/ab/, qr/abc/, ); my $text = 'aababc'; my @matches; foreach ($text) { # Safe $_ = $text; foreach my $re (@regexps) { push(@matches, /($re)/g); } } print("$_\n") foreach @matches;
a (at pos 0) a (at pos 1) a (at pos 3) ab (at pos 0) ab (at pos 3) abc (at pos 3)
Remove the "g" from "/($re)/g" to match each regexp only once.
|
|---|