Re: how to get references from imbricated capturing parenthesis ?



On 6/29/07, marin <marin.jb@xxxxxxxxx> wrote:

I'm trying to get references from a simple regular exepression like
this :

"a40d7412" =~ /(([[:xdigit:]]{2})*)/;

print "$1: <$2><$3><$4><$5>\n";

How to get all references and not the last one in the second
parenthesis pair ?

I don't think you're looking for references; those are described in
the perlref manpage. You're using regular expressions, described in
the perlre manpage (and elsewhere). Is that the source of your
confusion?

I think you're looking to get every hex digit pair you can match,
maybe? You could use m//g in list context:

my @matches = "a40d7412" =~ /([[:xdigit:]]{2})/g;

But that may not be what you want, especially if your data isn't just
hex. Good luck with it!

--Tom Phoenix
Stonehenge Perl Training
.