[Israel.pm] Re: Unknown number of captures

Yosef Meller mellerf at netvision.net.il
Wed Jan 28 08:38:08 PST 2004

Uri Itscowits <uri at itzko.hopto.org> Wrote:
 > #!/usr/bin/perl  to all,
 > I want to run a capturing regex, with an unknown number of captures 
as a result,
 >  how do I refer to the resulting list?
 > for example :
 > regex like:  /(Ab)/g
 > TIA

I wrote:
 > The @- array holds the begining index of all successful matches, the @+
 > array the end indexes. the number of captures will be "scalar @-".
 > perldoc perlvar has a lot to say aboput it including some dood examples.

Fix - This works for subgroups in the same match. for the /g option,
there's a "\G" special regex assertion that matches right aftwer the
last successful match. So I guess you could do something like:

while (/\G(Ab)/g) {
	print "Match: " . $i++;
	print "Subgroups: " . @-;
	# ... etc
perl -e'$b=unpack"b*",pack"H*","59dfce2d6b1664d3b26cd9969503";

My public key:

More information about the Perl mailing list