Regex Escape Dot – Match a Literal Period Instead of Any Character

Local only

Fix a valid regex whose unescaped dot matches an unexpected character instead of a literal period.

4 chars · 1 line

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex escaping behavior

How to escape a dot in a regular expression

A plain . is a wildcard in JavaScript regex syntax. That is why v1.2 matches v1x2. Use \. when the pattern is supposed to contain an actual period such as a version, hostname, or file extension separator. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Valid regex behavior check
  • Literal dot comparison
  • Wildcard debugging
  • Match or No match output
  • JavaScript RegExp semantics
  • Browser-local processing

Steps

  1. Find dots that represent literal punctuation in the value you want to match.
  2. Replace each literal period with \.
  3. Retest an input that differs only at the dot position to verify the wildcard is gone.

Dot is a wildcard unless escaped

Outside a character class, . normally matches a single character other than a line terminator. Escaping it changes the token from wildcard behavior to the literal period character.

Literal dot regex example

Escape the version separator so x no longer satisfies the pattern.

Wildcard pattern

v1.2

Literal-dot pattern

v1\.2

Common questions

Frequently asked questions

Why does . match x in my regex?

Because . is a wildcard metacharacter, not a literal period, unless it is escaped.

Do dots inside a character class need the same escaping?

Inside a character class, dot normally loses its wildcard meaning, but explicit escaping can still make intent easier to read.

Why do I sometimes see two backslashes in source code?

A JavaScript string literal may need its own escaping before the regex engine receives the backslash. In this tester, enter the regex pattern directly.

Debugging a specific Regex issue? Browse Regex troubleshooting.