in reply to regex extraction for variable number of args
Its got something to do with $2 being a scalar, and being able to contain only a single value -- try the following with -Mre=debug
$ perl -le " $_ = q{abcdef}; print for m{(.)(.)}g; a b c d e f $ perl -le " $_ = q{abcdef}; print for m{(.)(.)*}g; a f
So I think the (old) idiom is this
$cmd=q|&COMPAREEQUAL(First-param.one, Second.param,Third-param)|; my $re = qr{ \G (?: \& | (\w+) # $1 \( | (?: ( # $2 [^,\)\s]+ ) | (?: [,\s]+ ) ) | \) ) }mx; while( $cmd =~ m{$re}g ){ use Data::Dump; dd [ $1, $2 ]; } __END__ [undef, undef] ["COMPAREEQUAL", undef] [undef, "First-param.one"] [undef, undef] [undef, "Second.param"] [undef, undef] [undef, "Third-param"] [undef, undef]
Double-undef is when the non $1/$2 parts match
|
|---|