http://qs321.pair.com?node_id=264179

dextius has asked for the wisdom of the Perl Monks concerning the following question:

Caveat: Please do not offer split as my solution, this is geared more as a regular expression issue...

Let's use CSV as an example..

my $foo = "foo,bar,moo,cow"; $foo =~ /(?:([^,]+),)+/;

The above will only set $1 to "moo".. $2,$3,$4 are all null, $' is "cow", and $& is "foo,bar,moo"

I thought maybe the @- or @+ arrays might contain all of the matches, but to no avail...

What is strange is..

my $mystr = "foo,bar,moo,cow"; my @values = $mystr =~ m/(\w+)\,?/g;

@values will have all the matches I wanted.. But again, $1 will be set, and $2, $3, $4 will all be null.. Are capturing parentheses locked to $1 if matched multiple times? Is there any way around this? (without using split?)

Advance <- Thanks