Regex Cheat Sheet

A searchable regex cheat sheet with copy-ready examples for anchors, character classes, quantifiers, groups, lookaround and flags. Free, in your browser.

Showing 64 of 64

Anchors

^
Start of the string (or line, with the m flag)
^Hello
$
End of the string (or line, with the m flag)
world$
\b
Word boundary — edge between a word and non-word character
\bcat\b
It matches in three places: at the start of the string when the first character is \w; between two adjacent characters when one is \w and the other is \W; and at the end of the string when the last character is \w.
\B
Not a word boundary
\Bcat

Character classes

.
Any character except a line break
h.t
Inside a character set it loses that power: [.] is a literal period, no escape needed.
\d
Any digit, 0–9
\d\d
\D
Any character that is not a digit
\D+
\w
Word character: letter, digit or underscore
\w+
\W
Any non-word character
\W
\s
Any whitespace (space, tab, line break)
a\sb
\S
Any non-whitespace character
\S+
[abc]
Any one of the listed characters
[aeiou]
[^abc]
Any character NOT listed
[^0-9]
[a-z]
Any character in the given range
[a-z0-9]
[ ]
A literal space — the space bar itself, written inside a set so you can see it
a[ ]b

Inside a character set

[\\]
A backslash inside a set — one of only two characters that always needs escaping there
[\\/]
[\]]
A closing bracket inside a set — the other one that always needs escaping
[a\]]
[a^]
A caret is literal unless it is the FIRST character in the set
[a^b]
Escape it only right after the opening bracket: [\^a] matches a caret, [^a] matches anything that is not "a".
[a\-z]
An escaped hyphen — a literal "-" between two letters or two digits
[a\-z]
A hyphen only needs escaping between two letters or two digits, where it would otherwise make a range. At either end of the set — [-a] or [a-] — it is already literal.
[.]
A literal period — no escape needed inside a set
3[.]14

Quantifiers

*
Zero or more of the preceding token
ab*
The quantifier goes AFTER the expression it repeats — ab* repeats the b, (ab)* repeats both.
+
One or more of the preceding token
ab+
?
Zero or one — makes it optional
colou?r
{n}
Exactly n times
\d{4}
{n,}
n or more times
\d{2,}
{n,m}
Between n and m times (inclusive)
\d{2,4}
*?
Lazy: as few as possible
<.*?>
+?
Lazy one or more: as few as possible
".+?"

Groups & references

(…)
Capturing group — remembers the match
(ab)+
What it captured reaches only three methods: string.match(regexp), string.matchAll(regexp) and string.replace(regexp, callback).
(?:…)
Non-capturing group — groups without saving
(?:ab)+
(?<name>…)
Named capturing group
(?<year>\d{4})
|
Alternation — match the left OR the right
cat|dog
\1
Backreference to capturing group 1
(\w)\1
\k<name>
Backreference to a named group
(?<a>\w)\k<a>

Lookaround

(?=…)
Positive lookahead — followed by …
\d(?=px)
(?!…)
Negative lookahead — NOT followed by …
\d(?!px)
(?<=…)
Positive lookbehind — preceded by …
(?<=\$)\d+
(?<!…)
Negative lookbehind — NOT preceded by …
(?<!\$)\d+

Escapes

\.
A literal dot (escaped metacharacter)
3\.14
Outside a character set these twelve need the backslash: . ^ $ | \ / ( ) [ ] { }. Inside a set only two do — \\ and \] — and ^ and - are positional.
\^
A literal caret — the character, not the start-of-string marker
\^2
\$
A literal dollar sign — the character, not the end-of-string marker
\$5
\|
A literal pipe — the character, not alternation
a\|b
\\
A literal backslash
C:\\dir
\/
A literal forward slash — needed inside a /…/ literal, optional in new RegExp()
https:\/\/
\(
A literal opening parenthesis — the character, not a group
\(note\)
\)
A literal closing parenthesis
\(1\)
\[
A literal opening bracket — the character, not a character set
\[TODO\]
\]
A literal closing bracket
\[x\]
\{
A literal opening brace — the character, not a repeat count
\{name\}
\}
A literal closing brace
\{0\}
\t
A tab character
a\tb
\n
A newline (line-feed) character
line1\nline2
\r
A carriage return — the CR half of a Windows CRLF line ending
line1\r\nline2

Flags

g
Global — find all matches, not just the first
/\w+/g
i
Case-insensitive matching
/abc/i
m
Multiline — ^ and $ match at line breaks
/^a/m
s
Dotall — . also matches line breaks
/a.b/s
u
Unicode mode — full code-point matching
/\u{1F600}/u
y
Sticky — match starting at lastIndex only
/\d/y

Common patterns

[\w.+-]+@[\w-]+\.[\w.-]+
Email address
you@site.com
https?://\S+
HTTP or HTTPS URL
https://example.com
\b(?:\d{1,3}\.){3}\d{1,3}\b
IPv4 address
192.168.0.1
#[0-9a-fA-F]{6}\b
Hex colour code
#ff8800
\d{4}-\d{2}-\d{2}
ISO date (YYYY-MM-DD)
2026-08-17

Want to test a pattern against your own text? Open the Regex Tester →

The full rules: MDN — Regular expressions guide · RegExplained — take a pattern apart

🔒 A static reference — nothing is uploaded.

A searchable regular-expression reference

Search across regex tokens, their plain-language meanings, categories and examples to find the exact syntax you need — anchors, character classes, quantifiers, capturing and non-capturing groups, lookahead and lookbehind, flags, and ready-made patterns for emails, URLs, IPv4 addresses and dates. Every token comes with a short example and a one-click copy button. It is a static reference, so nothing is uploaded.

Cheat sheet, then tester

Use this page to recall the syntax, then open the Regex Tester to run your pattern against real text and watch matches and capture groups highlight live. The reference follows JavaScript (ECMAScript) regex syntax — the same flavour used by browsers and Node.js.

Frequently asked questions

What regex flavour does this cheat sheet use?

JavaScript (ECMAScript) regular expressions — the same engine built into browsers and Node.js. Most tokens also apply to other languages, though lookbehind and named-group syntax can differ.

Can I test a pattern here?

This page is a reference for looking up syntax. To run a pattern against your own text with live match highlighting, open the linked Regex Tester tool.

How do I match a literal special character?

Escape it with a backslash so the engine treats it as plain text instead of a metacharacter. The Escapes section of the cheat sheet lists the common ones.