Quantifiers
Quantifiers add optional quantity data to a regular expression. A quantifier expression applies to the character, group, or character class that immediately precedes it. The .NET Framework regular expressions support minimal matching ("lazy") quantifiers.
The following table describes the metacharacters that affect matching. The quantities n and m are integer constants.
Quantifier | Description |
---|---|
* |
Specifies zero or more matches; for example, |
+ |
Specifies one or more matches; for example, |
? |
Specifies zero or one matches; for example, |
{n} |
Specifies exactly n matches; for example, |
{n,} |
Specifies at least n matches; for example, |
{n,m} |
Specifies at least n, but no more than m, matches. |
*? |
Specifies the first match that consumes as few repeats as possible (equivalent to lazy *). |
+? |
Specifies as few repeats as possible, but at least one (equivalent to lazy |
?? |
Specifies zero repeats if possible, or one (lazy |
{n}? |
Equivalent to {n} (lazy {n}). |
{n,}? |
Specifies as few repeats as possible, but at least n (lazy {n,}). |
{n,m}? |
Specifies as few repeats as possible between n and m (lazy {n,m}). |