in reply to Matching regular expressions question
If you use the //g modifier in a scalar context, then the next match attempt, from the same regex or a another, will continue from where the last match occured. This is used to good effect when //g is used in conjunction with a while loop to process all the possible matches one at a time:
while( $string =~ m/$re/g ) { ## process all matches one at a time }
By calling your first regex with //g and in an if condition (scalar context), you are asking for the first match for that regex, and then asking for the next regex to continue the search from that position. But, as this is an if statement you're never going to loop back to process any second (or subsequent) match to the first regex.
In summary, drop the //g modifiers and you'll probably get the results you are looking for.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching regular expressions question
by Ninth Prince (Acolyte) on May 26, 2008 at 23:55 UTC |