in reply to Re^2: How do I avoid regex engine bumping along inside an atomic pattern?
in thread How do I avoid regex engine bumping along inside an atomic pattern?

You don't need to set pos($str) to 0 at the beginning - it is automatically undef which does the same thing. However you do need to reset it after every failed match before you try to match again.

But you do need to use \G or else you get your original problem. Using a \G at the start of your RE says, "Does this match right where I left off?" Leaving it out means, "Search from where I left off to find where it matches." So the latter will search ahead and find matches inside comments. The former can have the logic to know whether it is inside a comment or not. The latter does not.

About the second test, I suspect you didn't say exactly what you meant to say in the original question...

  • Comment on Re^3: How do I avoid regex engine bumping along inside an atomic pattern?