Course contentsShow
← JavaScript
Lesson 1669 of 2,72336. Regular ExpressionsFree lesson

The Dot Metacharacter

Using . to match any single character except newlines in default mode.

The Dot Metacharacter

You'll learn how the . character in regex patterns matches (almost) any single character.

What the Dot Does

In regular expressions, the dot (.) is a special metacharacter that acts like a wildcard. It matches any single character in your string—letters, digits, spaces, symbols—with one important exception: by default, it does not match newline characters (\n).

Think of the dot like a blank space in a crossword puzzle: it can be filled by any letter, but it occupies exactly one square.

How It Works

When you write a pattern like /c.t/, the dot says "match a c, followed by any single character, followed by a t". This would match "cat", "cot", "cut", or even "c@t" or "c9t".

const pattern = /c.t/;

pattern.test("cat");   // true
pattern.test("cot");   // true
pattern.test("c@t");   // true
pattern.test("ct");    // false — no character between c and t
pattern.test("cart");  // true — matches 'car' (c + a + r)

The Newline Exception

By default, . stops at newlines. If your string contains "c\nt", the pattern /c.t/ won't match because \n is excluded:

const pattern = /c.t/;
pattern.test("c\nt");  // false — dot doesn't match newline
pattern.test("c t");   // true — dot matches space just fine

(You'll learn how to change this behavior with flags later.)

When to Use the Dot

Use . when you genuinely don't care what character appears in a position—perhaps you're looking for a pattern structure rather than specific content. But don't overuse it; more specific patterns are usually clearer and safer.

Key Takeaway: The dot (.) matches any single character except newlines, making it a flexible wildcard in your regex patterns.