3 ms·
Weren't those called "lazy" quantifiers (vs. greedy quantifiers)? Edit: D'oh, I was mixing these up non-backtracking subexpressions with lazy ones. Thanks!
by dataflow 4y ago
Weren't those called "lazy" quantifiers (vs. greedy quantifiers)?
Edit: D'oh, I was mixing these up non-backtracking subexpressions with lazy ones. Thanks!
- josephcsible 4y agoPossessive is different from both greedy and lazy. It's like greedy except that it won't give back anything it matches, even if doing so would be necessary for the full pattern to match. See https://stackoverflow.com/q/5319840/7509065 https://stackoverflow.com/q/5319840/7509065 for a more detailed explanation.
- asicsp 4y agoLazy will match as minimally as possible, in contrast to greedy which match as much as possible. Both lazy and greedy quantifiers will backtrack to allow overall regex to match. Possessive on the other hand will not backtrack (unless it is part of a group having lazy/greedy quantifiers). A simple example: `error.*valid` or `error.*?valid` will match `error: invalid input` but `error.*+valid` will no match because `.*+` will consume rest of the characters without giving back to allow overall regex to match.