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
^Anchor to the start of the input.
eMatch "e".
xMatch "x".
aMatch "a".
mMatch "m".
pMatch "p".
lMatch "l".
eMatch "e".
.Match any character.
cMatch "c".
oMatch "o".
mMatch "m".
$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.