[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";
for(;$a<length$b;$a+=9){print+pack"b8",substr$b,$a,8;}'
My public key:
http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=0x3D2CA0A8
More information about the Perl
mailing list