I would suggest just storing the matches into an array. From there, you could easily access each element and also retrieve the number of elements in that array. The untested code below illustrates my idea.
my($text) = "(network)(test)(ifcfg)"; my(@matches) = ($text =~ m/\((.*?)\)/g); my $match_count = scalar(@matches); print "The following $match_count matches were found:\n"; foreach my $match (@matches) {print " $match\n";}
In the second line, I'm searching $text for all items that are within a set of parentheses and putting each match found into the @matches array. If you test this out with varying values for $test, the match finding part will still work correctly.
In reply to Re: Extracting multiple matches from Reg Ex
by dasgar
in thread Extracting multiple matches from Reg Ex
by rookie_monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |