in reply to Greedy match and zero-width negative lookahead assertion
Greedy means the longest valid match. aaa isn't valid (because followed by b) so the longest match is aa (which is a series of 'a's not followed by b, exactly what you asked for). Adding a + to a quantifier, making it possessive, will prevent partial backtracking though (meaning if a given subpattern can match a longer string, it is the only string that it can accept). So /^a{2,}+(?!b)/ will work as expected. /^a{2,}(?![ab])/ is another solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Greedy match and zero-width negative lookahead assertion
by jeffatrobertsdotnet (Initiate) on Mar 16, 2018 at 16:52 UTC |