Token-by-token breakdown
| Token | Meaning | Example |
|---|---|---|
^ |
Anchor: asserts the position at the start of the string | Start of '123.456.7890' |
\d |
Digit character class: matches any digit (0-9) | Digit '1' in '123.456.7890' |
{3} |
Quantifier: exactly 3 occurrences of the preceding token | Three digits '123' |
\. |
Escaped literal dot: matches a literal '.' character | Dot '.' in '123.456.7890' |
\d |
Digit character class: matches any digit (0-9) | Digit '4' in '456' |
{3} |
Quantifier: exactly 3 occurrences of the preceding token | Three digits '456' |
\. |
Escaped literal dot: matches a literal '.' character | Dot '.' in '456.7890' |
\d |
Digit character class: matches any digit (0-9) | Digit '7' in '7890' |
{4} |
Quantifier: exactly 4 occurrences of the preceding token | Four digits '7890' |
$ |
Anchor: asserts the position at the end of the string | End of '123.456.7890' |
Matches
123.456.7890000.111.2222999.888.7777
Does not match
1234567890123-456-7890123.456.789123.456.78900abc.def.ghij123.456.7890
Common pitfalls
- Forgetting to escape the dots (\.), which would match any character instead of a literal dot.
- Not anchoring the pattern with ^ and $, allowing extra characters before or after the phone number.
- Assuming this matches all phone number formats (e.g., with dashes or parentheses).
- Overlooking that \d matches any digit, including non-ASCII digits in some regex flavors.
Performance notes
This pattern is efficient with no risk of catastrophic backtracking. Anchors (^ and $) ensure the entire string is validated, preventing partial matches. No nested quantifiers or complex groups are present.