Literal dot

2 snippets in Regular Expressions

RXRegular Expressions

Escaping Special Characters

RX · Basic Patterns
Syntax
\. \* \+ \? \( \) \[ \] \{ \} \^ \$ \| \\
Example
JS:  'Price: $9.99'.match(/\$\d+\.\d{2}/)
Py:  re.search(r'\$\d+\.\d{2}', 'Price: $9.99')
Output
"$9.99"

Note All special regex characters must be escaped with a backslash to match literally. The special characters are: . * + ? ( ) [ ] { } ^ $ | \. In Python raw strings (r'...'), you only escape for regex, not for Python itself.

Dot Inside Character Class

RX · Character Classes
Syntax
[.]  matches a literal period (no escaping needed)
Example
JS:  'v2.1.0'.match(/[.]/g)
Py:  re.findall(r'[.]', '192.168.0.1')
Output
JS: [".", "."]
Py: [".", ".", "."]

Note Inside a character class, the dot loses its special meaning and matches a literal period. Both [.] and \. work for matching periods, but [.] can be more readable.

Frequently asked questions

How does Regular Expressions handle literal dot?
Regular Expressions covers this with 2 copy-ready snippets on this page. The "Escaping Special Characters" snippet in Regular Expressions uses `\. \* \+ \? \( \) \[ \] \{ \} \^ \$ \| \\`.
Which pattern does the Regular Expressions example use?
The "Escaping Special Characters" snippet uses `\. \* \+ \? \( \) \[ \] \{ \} \^ \$ \| \\`, from the Basic Patterns section of the Regular Expressions cheat sheet.
What other Regular Expressions snippets are shown for "literal dot"?
Besides "Escaping Special Characters", this page also shows "Dot Inside Character Class".
Is there anything to watch out for?
Yes. For "Escaping Special Characters": All special regex characters must be escaped with a backslash to match literally. The special characters are: . * + ? ( ) [ ] { } ^ $ | \. In Python raw strings (r'...'), you only escape for regex, not for Python itself.