in reply to Why isn't this regex greedy?

(?!bar) is a negative lookahead assertion. It is zero width assertion, so it anchors the match but doesn't use any characters. (?!bar). matches a character which is not the start of a bar sequence.

So, with that in mind: ((?!bar).){1,5} matches as many characters as it can (up to 5, and at least 1) that is not the start of the character sequence bar.


DWIM is Perl's answer to Gödel