Specific Quantifiers {n,m}
Sometimes you need precise control over repetition counts. Curly braces let you specify exactly how many.
Exact Count
a{3} matches exactly three 'a' characters.
Notice aaaa and aaaaa each contain one match of three a's.
Range
a{2,4} matches between 2 and 4 'a' characters.
Minimum Count
a{2,} matches 2 or more 'a' characters (no maximum).
Practical Examples
ZIP Codes
Social Security Numbers
IP Address Octets
Character Counts
Repeated Patterns
Practice Playground
Try:
\d{3}- exactly 3 digits\d{4}- exactly 4 digits\d{2,4}- 2 to 4 digits[A-Z]{2}- exactly 2 uppercase
Quantifier Summary
| Pattern | Meaning |
|---|---|
{3} | Exactly 3 |
{3,} | 3 or more |
{3,5} | Between 3 and 5 |
{0,5} | Up to 5 (0 to 5) |
Key Takeaways
{n}matches exactly n times{n,m}matches between n and m times{n,}matches n or more times- These work with any element:
\d{3},[a-z]{2,5},(ab){2}

