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 Hello World

  • The lazy pattern <.+?> will match and

Documentation / Reference

Discover More
Card Puncher Data Processing
Antlr - Lexer Rule (Token names|Lexical Rule)

in Antlr. They are rules that defines tokens. They are written generally in the grammar but may be written in a lexer grammar file Each lexer rule is either matched or not so every lexer rule expression...
Multilingual Regular Expression Syntax (Pattern)

Regular expression are Expression that defines a pattern in text. This is therefore a language that permits to define structure of a text. They are a mathematically-defined concept, invented by Stephen...
Card Puncher Data Processing
Php - Regular expressions (Perl-compatible)

in Php are an implementation of Perl (PCRE) with the PCRE library (See ). Therefore, the syntax for patterns used in these functions closely resembles to Perl (PCRE) but not totally. See reference.pcre.pattern.differencesPerl...
Regexp - (Quantifier|Cardinality Indicators)

A quantifier defines the number of times that: character class of character grouped (or not) may be seen. It has three behaviors: a Greedy one: match longest possible string. This is the...
Regexp - Dot (Single Character pattern)

Dot . in a regular expression matches any character in the supported character set with this characteristic, by default: newline characters are not included without setting a flag. See matchnewline...
Regular Expression - Greedy Quantifier

Greedy quantifier A Greedy quantifier will match the longest possible string (ie they consume as much input as possible) whereas Lazy quantifier will match the shortest possible string. Match as few...
Regular Expression - Line (Beginning and End)

Page the definition of line boundary (EOL) in regular expression You can define the begining or the end of a line with boundary matcher boundary matcher Description ^ The beginning of a line...
Regular Expression - Meta-(symbols|characters) - Operator

There are two different sets of meta-characters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets. Operator...
Regular Expression - Question Mark (?)

The question mark (?) in a regular expression has several meanings and may define: a quantifier a lazy match a group name property a look-around (assertion) And to determine what is its meaning,...

Share this page:
Follow us:
Task Runner