in reply to Why isn't this regex greedy?

I may be totally off my rocker here but I think that perl will interpret:

$_ = 'fooxbarbar'; # Not greedy - why not? if(/(foo)((?!bar).){1,5}bar/){ print "1 Matched:$1 $2\n"; } else{ print "1 Not Matched\n"; }


exactly the same way it interprets your code from expression #1:

$_ = 'fooxbarbar'; # Not greedy - why not? if(/(foo)(((?!bar).){1,5})bar/){ print "1 Matched:$1 $2\n"; } else{ print "1 Not Matched\n"; }


(note the missing set of parentheses on the top, modified version of your expression)

The output of both is, in any case, the same. The salient point being that perl is not including the
{1,5}
in the backreference - thus making the expression non-greedy...?

There is a great little blurb on positive and negative lookahead that you might take a look at:

http://www.regular-expressions.info/lookaround.html

wonder if that makes sense....