Perl-Sensitive Sunglasses | |
PerlMonks |
Re: [Perl 5.14, regex]: Problems with /g, \G and pos()by moritz (Cardinal) |
on Oct 19, 2013 at 16:15 UTC ( [id://1058930]=note: print w/replies, xml ) | Need Help?? |
The problem is that your regex potentially matches zero characters, so a loop like
Would loop infinitely. To prevent that, perl has some extra magic asociated with zero-width matches and /g, which you observe here. The obvious solution is to not use a regex which can match zero characters. You can prevent resetting of pos by using the /gc modifiers.
In Section
Seekers of Perl Wisdom
|
|