'abcdef' =~ / ( abc ( def) ) /x; $1 -> 'abcdef' $2 -> 'def'
So you have two options here. You can either specify each matching group, or match in a loop. For instance:
use Data::Dumper; my $table_ref="!Frequency[A][B][C] ..some other text.."; ### Groups specified explicitly my $var_rx = qr / \[ ( [^\]]+ ) \] /x; my $file_rx = qr / ! ( [^\[]+ ) /x; my $regex = qr/^ $file_rx $var_rx $var_rx? $var_rx? $var_rx? \s ++.*/x; my @matches = ( $table_ref =~ /$regex/); print Dumper (\@matches); ## Loop my ($filename) = ($table_ref =~ /^ $file_rx /gcx ); my @vars; while ( $table_ref =~ /\G $var_rx/gcx ) { push @vars,$1; } print Dumper($filename,\@vars);
See perlre for an explanation of \G and /c
clint
In reply to Re: Regex - backreferencing multiple matches in one group.
by clinton
in thread Regex - backreferencing multiple matches in one group.
by why_bird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |