Regular Expression - (Lazy|Reluctant) Quantifier


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.


To make a match lazy, you add a question mark after the greedy quantifier.


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


Hello World

For example in the termhello

  • the greedy h.+l matches hell
  • but the lazy h.+?l matches hel.


<em>Hello World</em>
  • The greedy pattern <.+> will match <em>Hello World</em>
  • The lazy pattern <.+?> will match <em> and </em>

Documentation / Reference

Powered by ComboStrap