Cheatsheet
← All cheat sheets

Regular expressions

Regular expressions describe text patterns for search and replace. This syntax works in JavaScript, Python, PHP, Java, VS Code and most other tools.

Characters

Any character except a new line
A digit 0–9 (\D: anything but a digit)
A letter, digit or _ (\W: anything else)
Whitespace: space, tab, new line (\S: anything else)
A real dot: put \ before . * + ? ( ) [ ] { } ^ $ | \
New line (\t: tab)

Character classes

a, b or c
Anything except a, b or c
Any lowercase letter
Any letter or digit
A dash or a dot (no escaping needed inside [ ])

Anchors

Start of the text (or line, with the m flag)
End of the text (or line, with the m flag)
Word boundary: \bcat\b matches “cat” but not “catalog”

Quantifiers

0 or more
1 or more
0 or 1 (optional)
Exactly 3
2 to 5
2 or more
As few as possible (lazy); works after * + ? {}

Groups and alternatives

Group, and remember the match as $1 / \1
Group without remembering
Named group
cat or dog
Back-reference: the same letter twice

Lookarounds

a followed by b (b is not part of the match)
a not followed by b
Digits right after a $ sign
Digits not right after a minus

Flags

Global: find every match, not just the first
Ignore upper/lower case
Multi-line: ^ and $ work per line
Dot also matches new lines
Unicode: emoji and accented letters count as one character

Handy patterns

Looks like an email address
A web address
A date like 2026-10-18
A hex color like #0b6a8a
A phone number (loose)
Spaces at the start or end (replace with nothing to trim)
Two or more spaces in a row
Something not working?

Send feedback

What is it?

The page you’re on, your browser and your screen size are sent along to help us fix it. Never your files or what you typed into the tool.