in reply to Why isn't this regex greedy?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Lazy vs Inchworm (was: Re^2: Why isn't this regex greedy?)
by merlyn (Sage) on Mar 17, 2006 at 14:40 UTC | |
|
Re^2: Why isn't this regex greedy?
by Melly (Chaplain) on Mar 17, 2006 at 10:20 UTC | |
by demerphq (Chancellor) on Mar 17, 2006 at 10:44 UTC |