Skip to main content
Module 1 · Lesson 3 of 43/32 in the course~15 min
Module lessons (3/4)

The wildcard: the dot `.`

The dot . is the wildcard par excellence of regexes: it matches any single character except for line terminators (\n). It is indispensable for flexible masks of known format, but requires attention because without limits it tends to consume more text than necessary.

Mental model: behavior of the point and flag s

PatternsFlagsTest inputsResult on \n / contentTechnical reason
c.tgcat c@t c\ntMatcha cat and c@t, skip c\ntBy default . excludes \n
c.tgscat c@t c\ntMatcha all three (c\nt included)The s (dotAll) flag enables . over \n
<p>.*</p>gs<p>A</p><p>B</p>Only one match of the entire row* is greedy (greedy)
<p>.*?</p>gs<p>A</p><p>B</p>Two separate matches.*? is lazy and stops at the first </p>

Progressive examples

1. Fixed-length single wildcard with .

Text
Pattern: c.t     (flag g)
Sample:  cat cot c-t c@t c\nt
         ^^^ ^^^ ^^^ ^^^

2. Traversing a multiline block with flag s (dotAll)

JS
const htmlBlock = '<p>prima riga\nseconda riga</p>';
console.log(/<p>.*<\/p>/.test(htmlBlock)); // false (bloccato su \n)
console.log(/<p>.*<\/p>/s.test(htmlBlock)); // true (dotAll attivo)

3. Separate multiple blocks without merging them (.*? vs .*)

Text
Sample:  [A] testo [B]
Pattern: \[.*\]   -> "[A] testo [B]"   (un unico match troppo largo)
Pattern: \[.*?\]  -> "[A]" e "[B]"     (due match distinti)

4. Turn s (dotAll) and g on and off live

Guided laboratory

Practice Stage

3 wildcard match in brackets

Exercise#regex.m1.l3.e1
Attempts: 0Loading…

Finds any exact triplet of any 3 characters enclosed in parentheses, such as (abc) or (123).

Loading editor…
Show hint

Activate the g flag by keeping the three dots between escape brackets \(...\).

Solution available after 3 attempts

Practice Stage

Multiline blocks delimited with s+lazy flag

Exercise#regex.m1.l3.e2
Attempts: 0Loading…

Extract every block between [INIZIO] and [FINE] even when it contains newlines (\n), stopping at the first closure (.*?) with flag gs.

Loading editor…
Show hint

Use \[INIZIO\].*?\[FINE\] and enable both the g and s flags.

Solution available after 3 attempts

Practice Stage

Wild card pattern respecting the newline border

Exercise#regex.m1.l3.e3
Attempts: 0Loading…

Find all sequences of exactly 3 characters starting with c and ending with t (e.g. cat, cot, c-t, c.t).

Loading editor…
Show hint

Replace the central letter with the wildcard . keeping only the flag g.

Solution available after 3 attempts

Check for understanding

Regex Quiz#regex.m1.l3.e4
Ready

What is the result of 'a\nb'.match(/a.b/)?

Answer options
Regex Quiz#regex.m1.l3.e5
Ready

Which string is accidentally matched by the unescaped pattern /10.5/ (default flags)?

Answer options