In a JavaScript regular expression, an unescaped . is a wildcard: it matches any single character except line terminators. Escape it as \. when you need a literal period.
Remember
. → any one character (not a line break)
\. → literal period only
.+ → one or more characters (greedy)
.* → zero or more characters
/s → dotAll: . also matches newlines
/c.t/ matches "cat", "cut", "c9t"
/\.pdf$/ matches "file.pdf" — not "fileXpdf"
Place the dot where one unknown character should sit, then decide whether you need a literal period or newlines.
Write a pattern with . for each unknown single character (for example /c.t/).
Escape real periods as \. in versions, decimals, and file extensions.
Add a quantifier (+, *, {n}) when you need a run of characters.
Add the s flag when the match must cross line breaks.
Piece
Required?
Role
. in the pattern
Yes (for wildcard)
Match exactly one non-line-break character
Escape \.
When needed
Match a real period character
Quantifier
Optional
Repeat the wildcard (.+, .*, .{3})
s flag
Optional
Let . match newlines (ES2018)
Pseudocode
Pseudocode
pattern has a "." at position p
read next character ch from the string
if ch is a line terminator AND flag "s" is off:
fail this path
else:
accept ch as the match for "."
continue with the rest of the pattern
if pattern used "\." instead:
accept only when ch is the period character "."
Reference
Cheat Sheet
Keep these facts handy while writing wildcard patterns.
Topic
Detail
Wildcard
. = one character (default: not a newline)
Literal period
\. or [.] inside a character class
One or more
.+ (greedy) / .+? (lazy)
Exact count
.{3} = exactly three characters
dotAll
/pattern/s — . includes newlines
Without s
[\s\S] also matches “any char including newline”
Standard
Dot: ES3+ · s flag: ES2018
Try it
Live Preview
Pick a pattern and see whether it matches the sample text with RegExp.prototype.test.
Browser demo of the RegExp . wildcard — same ideas as the examples below.
Result
pattern = /c.t/
text = "cat"
pattern.test(text)
→ true
/* "." matches the single character "a" */
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Wildcard Middle Character
Match three-character words that start with c and end with t.
Default rule. Without s, the . between start and end cannot match the newline.
Enable dotAll./start.end/s lets that single . match the newline character.
Inspect the flag.regex.dotAll is true when the s flag is set.
Longer spans. To skip many characters across lines, use /start.+end/s — one . alone is still one character.
Edge Cases & Pitfalls
Check these before relying on . in real projects.
trap
Bare . is never a literal period
In file names and decimals, write \.. Pattern /.pdf$/ also matches "Xpdf".
newline
No newline by default
Without the s flag, . fails on \n. Use /s or [\s\S] when you must cross lines.
greedy
.+ can over-capture
Greedy .+ takes as much as possible. Use .+? or a tighter class like \d / [a-z] when precision matters.
class
Inside [.] the dot is literal
In a character class, . usually means a real period — different from outside brackets, where it is a wildcard.
Compatibility
Browser & Runtime Support
The dot metacharacter is core regex syntax (ES3+). The dotAll s flag arrived in ES2018.
✓ Baseline · ES3+ / s ES2018
RegExp .
Wildcard . works in every browser and Node.js version. dotAll (s) is supported in Chrome 62+, Firefox 78+, Safari 12+, Edge 79+, and Node 10+.
98%Universal + modern s
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
.Excellent
Bottom line: Safe everywhere for basic .. Use the s flag for cross-line matching on modern runtimes; fall back to [\s\S] if you must support very old engines.
Analysis
Performance Notes
Approach
Cost
Best for
. / \.
O(1) per char
Single-character wildcards and literal dots
.+ / .*
Can backtrack
Flexible capture — tighten when possible
\d, \w, [a-z]
Usually clearer
When the character type is known
A lone . is cheap. Cost rises with greedy .+ on long strings and complex patterns. Prefer specific classes (\d, \w) when you do not need “any character.”
Remember
Key Takeaways
Role:. is a one-character wildcard (not a line break by default).
Literal period: use \. in versions, decimals, and extensions.
Quantifiers:.+ / .* for runs; prefer tighter classes when you can.
Newlines: add the s flag (dotAll) when . must cross lines.
One line:. means “any one character” — escape it as \. for a real period, and use /s when newlines should count.
Frequently Asked Questions
By default, . matches any single character except line terminators (\n, \r, U+2028, U+2029). It acts as a one-character wildcard for letters, digits, spaces, and punctuation on the same line.
An unescaped . is a wildcard. A literal period must be escaped: \. matches only the period character. For file extensions, use /\.pdf$/ not /.pdf$/.
Not by default. With the dotAll (s) flag—/pattern/s or regex.dotAll === true—. matches every character including newlines. That flag is ES2018.
.+ matches one or more of any character (greedy). .* matches zero or more. Use .+ when you need at least one character between other parts of the pattern.
Partially. /.../ matches exactly three characters, but they can be anything—not only letters. For letters only, prefer /[a-z]{3}/i or /\w{3}/.
The dot metacharacter is core regex syntax since ES3 and works everywhere. The dotAll (s) flag is ES2018: Chrome 62+, Firefox 78+, Safari 12+, Edge 79+, and Node.js 10+.