Regex Explainer

Why an unescaped dot matches too much

A pattern written for a domain name that also matches strings with no dot in them at all.

/^example.com$/

Match a whole string consisting of "e", then "x", then "a", then "m", then "p", then "l", then "e", then any character, then "c", then "o", then "m".

What to check

  • Probably a bug

    Unescaped dot matches any character

    A dot among literal characters matches ANY character, not a period. So a pattern written for "1.2" also matches "1x2", and one written for "example.com" matches "exampleXcom".

    Fix: Escape intended periods as \. — or use a character class [.].

  • Note

    Anchors match string ends, not line ends

    Without the m flag, ^ and $ match only the very start and end of the input — not the start and end of each line. On multi-line input this is often not what was intended.

    Fix: Add the m flag if the pattern should apply per line.

Step by step

  1. ^

    Anchor to the start of the input.

  2. e

    Match "e".

  3. x

    Match "x".

  4. a

    Match "a".

  5. m

    Match "m".

  6. p

    Match "p".

  7. l

    Match "l".

  8. e

    Match "e".

  9. .

    Match any character.

  10. c

    Match "c".

  11. o

    Match "o".

  12. m

    Match "m".

  13. $

    Anchor to the end of the input.

Details

Capture groups
None
Flags
None set

Check your own pattern

Paste one on the home page, or call the API or MCP server. This page is also available as markdown.

Related examples