in reply to Delving the regexp underdark -- how to understand \G's behavior, or how to loop through a regular expression

This is clearly not your actual code, not only because of the syntax error in your regexes that tilly pointed out, but also because, if it were your actual code (and the syntax error were fixed), then the second snippet would work.
#!perl undef $/; $text = <DATA>; while ($text =~/foo(.*?)bar/g) { manipulate ($1) } sub manipulate { print "@_\n"; } __DATA__ foo this is one example bar this is a line I don't care about foo here's another keeper! bar foo yet another bar and a line to reject
and the output:
this is one example here's another keeper! yet another
Please provide some code, whether it's your original code or a short snippet, that actually demonstrates the problem you are having.
  • Comment on Re: Delving the regexp underdark -- how to understand \G's behavior, or how to loop through a regular expression
  • Select or Download Code