The ((?!bar).){1,5} says match any sequence of characters of up to 5 characters so long as no part of those 5 characters is part of a "bar" string. It will match the most of those chars (up to the max) that it can, which means it is greedy. The zero width assertion prevents the greedyness from overruning. Its pretty well the same thing as:
/(foo)(.{1,5}?)bar/
Except I'd expect the latter to be more efficient.
In reply to Re: Why isn't this regex greedy?
by demerphq
in thread Why isn't this regex greedy?
by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |