Mike C wrote:
I'd like to iterate over each of a m//g style regex's FULL matches,
even
though it contains capturing groups. Then, for each FULL match, I'd
like to examine the capturing groups that are local to that match.
The thing I'm struggling with is that, while it's easy to iterate over
full matches when a regex does not contain capturing groups, the water
becomes muddy when you add capturing groups to the mix. See my little
test example below:
[ snip ]
# the theoretical output of this would look like this:
# re2 match #1 = ab
# group #1 = a
# group #2 = b
# re2 match #2 = cd
# group #1 = c
# group #2 = d
# re2 match #3 = ef
# group #1 = e
# group #2 = f
$ perl -e'
my $subject = qq(ab x cd y ef z);
my $re2 = qr/((\w)(\w))/;
my $matchcount;
while ( $subject =~ /$re2/g ) {
my $groupcount;
print "re2 match #" . ++$matchcount . " = $1\n", map "\t group #" .
++$groupcount . " = $_\n", $2, $3;
}
'
re2 match #1 = ab
group #1 = a
group #2 = b
re2 match #2 = cd
group #1 = c
group #2 = d
re2 match #3 = ef
group #1 = e
group #2 = f
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/