![]() |
|
Perl: the Markov chain saw | |
PerlMonks |
regex only matching from last matchby Foxpond Hollow (Sexton) |
on Sep 19, 2009 at 23:38 UTC ( #796325=perlquestion: print w/replies, xml ) | Need Help?? |
Foxpond Hollow has asked for the wisdom of the Perl Monks concerning the following question:
I was having a bear of a time recently trying to figure out why my regex wasn't matching correctly, until I finally tried changing where it came up. It turns out that it was only looking from wherever the last regex happened to leave off.
Here's the text it should be matching in: And here are the two regexes:
It works correctly now after I rearranged the regexes. However, before when I had the ISBN regex coming after, it would not match anything. I tried changing \d to just . to see where it would even land, and it was matching with "Democratic Pa," which would have been the next match after where the title regex matched. For the record, the correct matches should be "9780470086223" for the ISBN and "Heads in the sand : " for the title match. As far as I'm aware, a regex with the g flag should match globally, meaning it would ignore wherever another regex happened to stop searching. Is this not correct? If I am right, can someone tell me why I'm seeing this behavior, and how I might correct it? Thanks a lot. p.s. this is just a random example book and I don't mean to make any political statements by its use
Back to
Seekers of Perl Wisdom
|
|