Script Valley
Regex: Actually Useful Patterns
Quantifiers and Greedy vs Lazy MatchingLesson 4.4

Exact and range quantifiers in regex

exact quantifier, minimum quantifier, range quantifier, phone number pattern, input length validation, combining with anchors

Control Match Length Precisely

Range quantifiers

When * and + are too loose, use curly-brace quantifiers to specify exact or bounded repetition.

  • {n} โ€” exactly n times
  • {n,} โ€” at least n times
  • {n,m} โ€” between n and m times (inclusive)
/^\d{10}$/.test('4155550000')   // true  โ€” exactly 10 digits
/^\d{6,8}$/.test('123456')      // true  โ€” 6 digits

Always combine curly quantifiers with anchors for validation.

Up next

Possessive quantifiers and atomic groups to prevent backtracking

Sign in to track progress

Exact and range quantifiers in regex โ€” Quantifiers and Greedy vs Lazy Matching โ€” Regex: Actually Useful Patterns โ€” Script Valley โ€” Script Valley