Qaynaq LABS · TOOLS

REGEX · JAVASCRIPT

Regex explained

^\d{3}\.\d{3}\.\d{4}$

Matches strings that represent a 10-digit phone number formatted with dots as separators (e.g., 123.456.7890).

Token-by-token breakdown

TokenMeaningExample
^ 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.7890
  • 000.111.2222
  • 999.888.7777

Does not match

  • 1234567890
  • 123-456-7890
  • 123.456.789
  • 123.456.78900
  • abc.def.ghij
  • 123.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.

About regular expressions

Regular expressions are tiny programs that match patterns in text. They're powerful and notoriously cryptic — most engineers can write them but few can read them confidently. Qaynaq Labs' regex explainer breaks any pattern into its constituent tokens, shows what each one does, and runs through both matching and non-matching examples so you can verify the logic.

Different regex flavors (JavaScript, PCRE, Python, Go) have subtle differences in syntax and supported features. Pick your flavor in the input — the explainer accounts for it.

Frequently asked

Does this pattern match international phone numbers?

No, this pattern is designed for a specific 10-digit format with dots. International numbers may include country codes, different separators, or varying digit lengths.

Why are the dots escaped with backslashes?

In regex, a dot (.) is a metacharacter that matches any character except a newline. To match a literal dot, it must be escaped as \.

Can this pattern match phone numbers with leading or trailing spaces?

No, the anchors ^ and $ ensure the entire string must match the pattern exactly. Spaces would cause the pattern to fail.