Quantifiers
|
Previous Top Next |
· Zero or more (*)
This quantifier tells the expression to match zero or more instances of the proceeding term. For example "0." will match zero or more '0' characters.
This quantifier tells the expression to match zero or more instances of the proceeding term. For example "0." will match zero or more '0' characters.
· One or more (+)
This quantifier tells the expression to match one or more instances of the proceeding term. For example "0+" will match one or more '0' characters.
This quantifier tells the expression to match one or more instances of the proceeding term. For example "0+" will match one or more '0' characters.
· Zero or one (?)
This quantifier tells the expression to match zero or one instance of the proceeding term. For example "0?" will match zero or one '0' characters.
This quantifier tells the expression to match zero or one instance of the proceeding term. For example "0?" will match zero or one '0' characters.
· Exactly n ({n})
Matches exactly n instances of the proceeding term. For example "\d{5}" will match a 5 digit US zip code, and "\d{5}-\d{4}" will match a 5-4 US zip code.
Matches exactly n instances of the proceeding term. For example "\d{5}" will match a 5 digit US zip code, and "\d{5}-\d{4}" will match a 5-4 US zip code.
· At least n ({n,})
Matches at least n instances of the proceeding term.
Matches at least n instances of the proceeding term.
· At least n, but no more than m ({n,m})
Matches at least n, but no more than m instances of the proceeding term.
Matches at least n, but no more than m instances of the proceeding term.
· Make it lazy (<quantifier>?)
Adding a '?' to the quantifier makes the quantifier lazy. This means that the engine will accept the first minimal match, rather than the largest possible match. For example if the test string is "012345" and the regular expression is "\d{2,3}", then the matches will be "012" and "345". If we add the lazy qualifier, "\d{2,3}?", then the matches become "01", "23", and "45".
Adding a '?' to the quantifier makes the quantifier lazy. This means that the engine will accept the first minimal match, rather than the largest possible match. For example if the test string is "012345" and the regular expression is "\d{2,3}", then the matches will be "012" and "345". If we add the lazy qualifier, "\d{2,3}?", then the matches become "01", "23", and "45".
For detailed information on these constructs see the online reference at MSDN: