JavaScript RegExp Dot Metacharacter

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

What Is the Dot .?

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"
UsePrefer
Any one character.
Literal period\.
Digit only\d
Include newlines/pattern/s (dotAll)

How to Use .

Place the dot where one unknown character should sit, then decide whether you need a literal period or newlines.

  1. Write a pattern with . for each unknown single character (for example /c.t/).
  2. Escape real periods as \. in versions, decimals, and file extensions.
  3. Add a quantifier (+, *, {n}) when you need a run of characters.
  4. Add the s flag when the match must cross line breaks.
PieceRequired?Role
. in the patternYes (for wildcard)Match exactly one non-line-break character
Escape \.When neededMatch a real period character
QuantifierOptionalRepeat the wildcard (.+, .*, .{3})
s flagOptionalLet . 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 "."

Cheat Sheet

Keep these facts handy while writing wildcard patterns.

TopicDetail
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”
StandardDot: ES3+ · s flag: ES2018

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" */

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.

JavaScript
const pattern = /c.t/;

console.log(pattern.test("cat"));   // true
console.log(pattern.test("cut"));   // true
console.log(pattern.test("c9t"));   // true
console.log(pattern.test("cart"));  // false
Try It Yourself

How It Works

  1. Build the pattern. /c.t/ means: letter c, any one character, letter t.
  2. Fill the slot. In "cat" the dot matches "a"; in "cut" it matches "u"; in "c9t" it matches "9".
  3. Reject extras. "cart" has four characters in that span, so the pattern does not match.
  4. One char only. A single . never spans two characters.

Example 2 — Literal Period with \.

Escape the dot when you mean a real period in versions or file names.

JavaScript
console.log(/version \d+\.\d+/.test("version 2.4")); // true
console.log(/version \d+.\d+/.test("version 2X4"));  // true (wildcard!)

console.log(/\.txt$/.test("notes.txt")); // true
console.log(/\.txt$/.test("notesXtxt")); // false
Try It Yourself

How It Works

  1. Escape for data. \. matches only the period character in "version 2.4".
  2. Unescaped trap. \d+.\d+ lets the bare . match "X", so "version 2X4" incorrectly passes.
  3. File endings. /\.txt$/ requires a real . before txt at the end of the string.
  4. Rule of thumb. In extensions and decimals, always write \..

Example 3 — Match Across Lines with dotAll (s)

By default . stops at newlines. The s flag removes that limit.

JavaScript
const text = "start\nend";

console.log(/start.end/.test(text));   // false
console.log(/start.end/s.test(text));  // true

const regex = /start.end/s;
console.log(regex.dotAll);             // true
Try It Yourself

How It Works

  1. Default rule. Without s, the . between start and end cannot match the newline.
  2. Enable dotAll. /start.end/s lets that single . match the newline character.
  3. Inspect the flag. regex.dotAll is true when the s flag is set.
  4. 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.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · 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.

Performance Notes

ApproachCostBest for
. / \.O(1) per charSingle-character wildcards and literal dots
.+ / .*Can backtrackFlexible capture — tighten when possible
\d, \w, [a-z]Usually clearerWhen 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.”

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+.

Next: \f form feed

Learn how the form-feed metacharacter matches page-break control characters.

\f tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful