About
A Lazy quantifier will match the shortest possible string. Match as few as possible, repeat as few times as possible whereas a Greedy quantifier will match the longest possible string.
Articles Related
Syntax
To make a match lazy, you add a question mark after the greedy quantifier.
List
Lazy Quantifier | Description |
---|---|
X?? | X, once or not at all |
X*? | X, zero or more times |
X+? | X, one or more times |
X{n}? | X, exactly n times |
X{n,}? | X, at least n times |
X{n,m}? | X, at least n but not more than m times |
Example
Hello World
For example in the termhello
- the greedy h.+l matches hell
- but the lazy h.+?l matches hel.
HTML
<em>Hello World</em>
- The greedy pattern <.+> will match Hello World
- The lazy pattern <.+?> will match and