JavaScript RegExp . Metacharacter

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Wildcard

What You’ll Learn

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

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.

Understanding the . Metacharacter

In a regex pattern, an unescaped . matches exactly one character that is not a line terminator:

JavaScript
/c.t/.test("cat");   // true  ("." matches "a")
/c.t/.test("cut");   // true  ("." matches "u")
/c.t/.test("cart");  // false (extra char after pattern)

/./.test("");        // false (need one char)
/./.test("x");       // true

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.

How to Use . in JavaScript

Combine the dot with quantifiers and anchors for flexible matching:

JavaScript
"hello".match(/h.llo/);           // ["hello"]
"tag: blue".match(/tag: .+/);     // ["tag: blue"]
"file.txt".match(/\.txt$/);       // [".txt"]

"line1\nline2".match(/line1.line2/);   // null (dot skips newline)
"line1\nline2".match(/line1.line2/s); // match with dotAll

Use .+ for “everything until…” on one line, \. for literal dots, and the s flag when newlines must be included.

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

⚡ Quick Reference

GoalPattern
Any one character.
Literal period\.
One or more chars.+
Exactly 3 chars.{3}
Include newlines/pattern/s
Non-greedy match.+?

📋 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

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.

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

The dot stands in for exactly one character between c and t. Extra characters after the pattern cause test() to fail.

📈 Practical Patterns

Literal dots, greedy runs, extensions, and multiline matching.

Example 2 — Literal Period with \.

Match a real dot in decimal numbers or file names.

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

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

How It Works

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)
Try It Yourself

How It Works

.+ consumes characters greedily until the rest of the pattern can match. Use .+? for lazy (minimal) matching when needed.

Example 4 — Validate File Extension with \.

Ensure a filename ends with a literal dot and extension.

JavaScript
const pdfPattern = /\.pdf$/i;

console.log(pdfPattern.test("report.pdf"));  // true
console.log(pdfPattern.test("report.PDF"));  // true
console.log(pdfPattern.test("reportXpdf"));  // false
Try It Yourself

How It Works

\. requires an actual period before pdf. The i flag makes the extension case-insensitive.

Example 5 — Match Across Lines with dotAll (s)

Let . include newline characters when spanning blocks of text.

JavaScript
const text = "start\nmiddle\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

Without s, the dot cannot cross \n. The dotAll flag (ES2018) removes that restriction so . matches any character.

🚀 Common Use Cases

  • Flexible spelling — match variants with unknown middle characters.
  • File extensions — use \. before extension letters.
  • Version numbers — pattern \d+\.\d+ for major.minor.
  • Key-value parsing — capture values with /key: .+/.
  • Multiline blocks — dotAll for HTML or config sections spanning lines.
  • Length checks^.{8,}$ for minimum character count.

Important Considerations

  • Escape literal dots — unescaped . is always a wildcard, never a period.
  • Greedy .+ — can over-capture; use lazy .+? or specific classes when precision matters.
  • No newline by default — multiline text needs the s flag or explicit [\s\S].
  • Not “any string” — one dot equals one character; use quantifiers for longer runs.
  • Prefer specific classes — when you know the char type, \d or [a-z] is clearer than ..

🧠 How . Matches a Character

1

Reach the dot

The engine expects one character at the current position.

Wildcard
2

Check line rules

By default, reject newline chars unless dotAll is enabled.

Filter
3

Accept or reject

Any other single character satisfies the dot and matching continues.

Match
4

Quantifier next

If followed by + or *, repeat the dot rule.

📝 Notes

  • . = wildcard; \. = literal period.
  • dotAll (s flag) lets . match newlines (ES2018+).
  • Review \d when you need digits specifically, not any character.
  • Next up: \f form feed metacharacter.
  • 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.

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 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 dot. Use s flag for cross-line matching on modern runtimes.

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.

💡 Best Practices

✅ Do

  • Escape dots in file names: \.pdf
  • Use .+? when greedy capture is too much
  • Add s flag for multiline wildcard matching
  • Prefer \d, \w when char type is known
  • Anchor length checks: ^.{0,100}$

❌ Don’t

  • Use bare . when you mean a literal period
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about RegExp .

Use the dot as a flexible single-character wildcard.

5
Core concepts
📝 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.

Continue to \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.

6 people found this page helpful