LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

How do wildcards and multipliers work in regular expressions?

. matches any one character; quantifiers say how many times the previous thing repeats — * (0+), + (1+), ? (0 or 1), {n,m} (a range).

The trap that catches everyone: in regex, * is not a wildcard the way it is in shell globbing. It means "zero or more of the preceding item," so colou*r matches color, colour, colouuur. To match "any sequence of characters" you need .* (any char, repeated). And remember +, ?, {n,m} only work as operators in extended regex (grep -E); in basic regex they're literal unless escaped.

Pattern Meaning
. Any single character
* Zero or more of previous
+ One or more of previous (extended)
? Zero or one of previous (extended)
{n} Exactly n times
{n,m} Between n and m times

Examples:

# Any 3-letter word starting with c, ending with t
grep "c.t" file.txt    # cat, cut, cot, c5t

# "color" or "colour"
grep "colou*r" file.txt

# One or more digits (extended regex)
grep -E "[0-9]+" file.txt

# Optional "s" - "file" or "files"
grep -E "files?" file.txt

Character classes:

[abc]     # a, b, or c
[a-z]     # lowercase letter
[A-Z]     # uppercase letter
[0-9]     # digit
[^0-9]    # NOT a digit

Go deeper:

From Quiz: LIOS / Bash Scripting and Automation | Updated: Jul 14, 2026