The dot . is the regex wildcard: it matches almost any single character on a line. Use it for flexible patterns like c.t (cat, cut, cot), but escape it as \. when you need a literal period in file names or decimals.
01
Wildcard
.
02
One char
Single slot
03
Literal
\.
04
Quantifiers
.+
05
No newline
Default
06
dotAll
/s flag
Fundamentals
Introduction
Sometimes you know part of a pattern but not every character—like the middle letter in a three-letter word. The dot metacharacter fills that gap by matching one character of (almost) any kind.
By default, the dot does not cross line boundaries. That keeps multiline text safe unless you explicitly enable the dotAll (s) flag.
Concept
Understanding the . Metacharacter
In a regex pattern, an unescaped . matches exactly one character that is not a line terminator:
To match a real period in text (like .pdf), escape it: \.. Without the backslash, the dot remains a wildcard.
💡
Beginner Tip
In URLs and file names, always write \. for a literal dot. Pattern /\.jpg$/ matches "photo.jpg"; pattern /.jpg$/ would match "Xjpg" too because . is wildcard.
Usage
How to Use . in JavaScript
Combine the dot with quantifiers and anchors for flexible matching:
Use .+ for “everything until…” on one line, \. for literal dots, and the s flag when newlines must be included.
Foundation
📝 Syntax
JavaScript
. // any char except line break
\. // literal period
.+ // one or more (greedy)
.*? // zero or more (lazy)
.{3} // exactly three chars
/pattern/s // dotAll: . matches newline too
Common patterns
/c.t/ — three-char words starting with c, ending with t.
/\.(pdf|png)$/i — file extension with literal dot.
/^.{1,10}$/ — string length between 1 and 10 characters.
/start.+end/s — span across lines with dotAll.
Cheat Sheet
⚡ Quick Reference
Goal
Pattern
Any one character
.
Literal period
\.
One or more chars
.+
Exactly 3 chars
.{3}
Include newlines
/pattern/s
Non-greedy match
.+?
Compare
📋 Wildcard . vs Literal \. vs .+
Three dot-related patterns beginners confuse.
Wildcard
.
Any char
Literal dot
\.
Period only
Greedy run
.+
One or more
dotAll
/./s
+ newline
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Examples cover wildcards, literal dots, greedy matching, file extensions, and dotAll.
📚 Getting Started
Use . as a single-character wildcard in the middle of a pattern.
Example 1 — Wildcard Middle Letter with c.t
Match three-letter words that start with c and end with t.
The second test shows why escaping matters: unescaped . matches X as easily as a period. Use \. when the dot is part of the data.
Example 3 — Greedy .+ Capture
Grab everything after a label on the same line.
JavaScript
const line = "color: deep blue";
const greedy = line.match(/color: .+/);
console.log(greedy[0]); // "color: deep blue"
const lazy = "a1b2".match(/a.+b/);
console.log(lazy[0]); // "a1b" (.+ is greedy but stops at last possible b)
Alternative for “any char including newline”: [\s\S] works without the s flag.
In character classes [.], the dot is usually literal—no escape needed inside brackets.
Compatibility
Browser & Runtime Support
The dot metacharacter is universal regex syntax. The dotAll s flag requires ES2018+.
✓ Baseline · ES3+ / s ES2018
RegExp .
Wildcard dot works everywhere. dotAll (s flag) is supported in modern browsers 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 dot. Use s flag for cross-line matching on modern runtimes.
Wrap Up
Conclusion
The dot . is JavaScript’s single-character wildcard. It powers flexible patterns like c.t and greedy captures with .+, but must be escaped as \. for literal periods.
Remember the default newline restriction and reach for the s flag when dots should span lines. Next, learn the \f form feed metacharacter.
Assume . matches entire strings without quantifiers
Expect . to cross lines without the s flag
Overuse .+ where a precise class fits better
Forget that [.] inside brackets is a literal dot
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about RegExp .
Use the dot as a flexible single-character wildcard.
5
Core concepts
●01
Wildcard
.
Syntax
📝02
Literal
\.
Escape
📈03
.+
Greedy.
Quantifier
📄04
No \n
Default.
Rule
🌐05
dotAll
/s
Flag
❓ Frequently Asked Questions
By default, . matches any single character except line terminators (\n, \r, U+2028, U+2029). It acts as a wildcard for letters, digits, spaces, and punctuation on the same line.
An unescaped . is a wildcard. A literal dot must be escaped: \. matches only the period character. In 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.
.+ matches one or more of any character (greedy). .* matches zero or more. Use .+ when you need at least one character between anchors.
Partially. Pattern /.../ matches exactly three characters, but they can be anything—not necessarily letters. For letters only, use /[a-z]{3}/ or /\w{3}/.
The dot metacharacter is core regex syntax since ES3. The dotAll (s) flag was added in ES2018 and works in modern browsers and Node 10+.
Did you know?
Inside a character class, a dot is usually literal: [a.z] matches a, a literal dot, or z. That is different from outside brackets, where . is always a wildcard unless escaped.