Ninth Prince has asked for the wisdom of the Perl Monks concerning the following question:
I have a progarm where I basically run two regex matches in a row (on the same document). It seems like my ability to match depends on the ordering of the matches. The code looks something like this:
if ($content =~ m%match (pattern)%g) { $firstVariable = $1 ; } #end if if ($content =~ m%match (pattern2)%g) { $secondVariable = $1 ; } #end if
If I put one of the ifs first, both match, but if I reverse the ordering of the ifs, only one matches (the one first in order).
What's going on? Do I need to "reset" the search back to the beginning of the $content string? If so, how to do? Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching regular expressions question
by BrowserUk (Patriarch) on May 26, 2008 at 23:51 UTC | |
by Ninth Prince (Acolyte) on May 26, 2008 at 23:55 UTC | |
|
Re: Matching regular expressions question
by pc88mxer (Vicar) on May 26, 2008 at 23:43 UTC | |
by Ninth Prince (Acolyte) on May 26, 2008 at 23:49 UTC | |
|
Re: Matching regular expressions question
by ikegami (Patriarch) on May 27, 2008 at 00:48 UTC |