Regex Quantifiers

Repeat matchers: star, plus, ranges, and exact counts.

  • regex quantifier
  • greedy lazy
  • match phone
  • repeat pattern
  • regex star plus

Regex Quantifiers

Repeat matchers: star, plus, ranges, and exact counts.

Commands

CommandWhat it does
a*Zero or more
a+One or more
a?Zero or one (optional)
a{2,4}Between 2 and 4
a{3}Exactly 3
a{2,}Two or more

Example

^1[3-9]\d{9}$  # Chinese mobile number

FAQ

Why does my d-plus match too much?

It is greedy - pair it with boundaries or make it lazy when it over-matches.

How do I avoid catastrophic backtracking?

Use atomic groups or possessive quantifiers where supported, or narrow the repeated class.

Întrebări frecvente

Why does my d-plus match too much?
It is greedy - pair it with boundaries or make it lazy when it over-matches.
How do I avoid catastrophic backtracking?
Use atomic groups or possessive quantifiers where supported, or narrow the repeated class.

Regex