in reply to newbie to regex: all matches
The basic answer to that is the "g" modifier, placed at the end of the regex. Some examples:
$_ = <<ETX; Long text string foo_1... with multiple foo_2 lines... and who cares foo_3 what else... ETX while ( /foo_\d+(.*)/g ) { # loop over every match print "found '$1' between foo and end-of-line\n"; } s/foo_/bar=/g; # replace all occurrences of foo with bar my @bars = ( /(bar=\d+)/g ); # capture all occurrences to an array print "@bars\n";
|
|---|