Feature: Quantifiers
Home | Features | Improve this section
Quantifiers specify repetition of an Atom. By default, quantifiers are “greedy” in that they attempt to match as many instances of the preceding Atom as possible to satisfy the pattern before backtracking.
Syntax
NOTE: The following syntax is an example based on some of the supported engines. For specific engine support, see Engines.
*
— Matches the preceding Atom zero or more times. Example:a*b
matchesb
,ab
,aab
,aaab
, etc.+
— Matches the preceding Atom one or more times. Example:a+b
matchesab
,aab
,aaab
, etc., but notb
.?
— Matches the preceding Atom zero or one times. Example:a?b
matchesb
,ab
.{n}
— Where n is an integer. Matches the preceding Atom exactly n times. Example:a{2}
matchesaa
but nota
oraaa
.{n,}
— Where n is an integer. Matches the preceding Atom at-least n times. Example:a{2,}
matchesaa
,aaa
,aaaa
, etc., but nota
.{n,m}
— Where n and m are integers, and m >= n. Matches the preceding Atom at-least n times and at-most m times. Example:a{2,3}
matchesaa
,aaa
,aaaa
, etc., but nota
oraaaa
.
Engines
Engine | Supported |
---|---|
Perl | ✔ |
PCRE | ✔ |
Boost.Regex | ✔ |
.NET | ✔ |
Oniguruma | ✔ |
Hyperscan | ✔ |
ICU | ✔ |
Glib/GRegex | ✔ |
ECMAScript | ✔ |