E
ematiu
Hello list,
I have a regex in a variable, with an unknown number of submatches.
When I apply this regex to a string, how can I obtain all the
submatches in a array?
The submatches are returned in $1, $2 ..., but how can I know how many
are in total?
For example, if the number of submatches is 2:
$r='uid=(\d+).*groups=(\d+).*';
$str= `id`;
$str=~ /$r/;
@submatches=($1,$2);
but, now if
$r='uid=(\d+).*';
$str= `id`;
$str=~ /$r/;
@submatches=($1,$2); # how can I make this general??
Thanks!!
matías
I have a regex in a variable, with an unknown number of submatches.
When I apply this regex to a string, how can I obtain all the
submatches in a array?
The submatches are returned in $1, $2 ..., but how can I know how many
are in total?
For example, if the number of submatches is 2:
$r='uid=(\d+).*groups=(\d+).*';
$str= `id`;
$str=~ /$r/;
@submatches=($1,$2);
but, now if
$r='uid=(\d+).*';
$str= `id`;
$str=~ /$r/;
@submatches=($1,$2); # how can I make this general??
Thanks!!
matías