Regex Cheat Sheet

A searchable quick reference for regex syntax — click any card to copy.

Input data is processed in your browser
Data is never sent to a server

Tool

Anchors

^

Start of string or line (with m flag)

e.g.^Hello
$

End of string or line (with m flag)

e.g.world$
\b

Word boundary (between \w and \W)

e.g.\bword\b
\B

Non-word boundary

e.g.\Bend

Character Classes

.

Any character except newline

e.g.a.c
\d

Digit [0-9]

e.g.\d+
\D

Non-digit

e.g.\D+
\w

Word character [a-zA-Z0-9_]

e.g.\w+
\W

Non-word character

e.g.\W+
\s

Whitespace (space, tab, newline, etc.)

e.g.\s+
\S

Non-whitespace

e.g.\S+
[abc]

Any one of a, b, or c

e.g.[aeiou]
[^abc]

Any character NOT in a, b, or c

e.g.[^0-9]
[a-z]

Any character in range a to z

e.g.[a-zA-Z]

Quantifiers

*

0 or more (greedy)

e.g.ab*c
+

1 or more (greedy)

e.g.ab+c
?

0 or 1 (optional)

e.g.colou?r
*?

0 or more (lazy)

e.g.a.*?b
+?

1 or more (lazy)

e.g.a.+?b
??

0 or 1 (lazy)

e.g.a??b
{n}

Exactly n times

e.g.a{3}
{n,}

n or more times

e.g.a{2,}
{n,m}

Between n and m times (greedy)

e.g.a{2,4}
{n,m}?

Between n and m times (lazy)

e.g.a{2,4}?

Groups

(abc)

Capture group — reference via $1, $2 …

e.g.(\d+)-(\d+)
(?:abc)

Non-capturing group

e.g.(?:abc)+
(?<n>abc)

Named capture group

e.g.(?<year>\d{4})
(?=abc)

Positive lookahead

e.g.\d(?=px)
(?!abc)

Negative lookahead

e.g.\d(?!px)
(?<=abc)

Positive lookbehind

e.g.(?<=\$)\d+
(?<!abc)

Negative lookbehind

e.g.(?<!\$)\d+
(abc|def)

Alternation (OR)

e.g.(cat|dog)

Escape Sequences

\n

Newline

\r

Carriage return

\t

Tab

\0

NULL character

\\

Literal backslash

e.g.C:\\Users
\uXXXX

Unicode character (4 hex digits)

e.g.\u0041
\xXX

ASCII character (2 hex digits)

e.g.\x41
\1

Backreference to capture group 1

e.g.(\w+)\s\1
\k<n>

Named backreference

e.g.(?<w>\w+)\k<w>

Flags

g

Global — find all matches

e.g./abc/g
i

Case-insensitive

e.g./abc/i
m

Multiline — ^ and $ match line boundaries

e.g./^x/m
s

dotAll — . also matches newlines

e.g./a.b/s
u

Unicode — handle surrogate pairs correctly

e.g./\u{1F600}/u
v

unicodeSets — extended character classes (ES2024)

e.g./[\p{L}&&[^a]]/v
d

hasIndices — include match index info

e.g./abc/d
y

Sticky — match only at lastIndex position

e.g./abc/y

Replacement Tokens

$&

Entire match

e.g."$&"
$1 $2

Capture group 1, 2, …

e.g.$2, $1
$<n>

Named capture group

e.g.$<year>
$'

String after match

$`

String before match

$$

Literal dollar sign

What is the Regex Cheat Sheet?

The Regex Cheat Sheet is a searchable quick reference covering the most common regular expression syntax, organized into seven categories.

Anchors, character classes, quantifiers, groups, escape sequences, flags, and replacement tokens are all included. Click any card to copy its syntax instantly — ready to paste into your editor or code.

How to Use

  1. Type in the search box to filter entries by syntax, description, or keyword in real time.
  2. Click a category button to narrow results to anchors, quantifiers, groups, and more.
  3. Click any card to copy its syntax directly to your clipboard.

FAQ

Which regex flavor is this based on?

This cheat sheet is based on the JavaScript ECMAScript regex engine. Most syntax is shared with Python, Java, Go, PHP, and other languages, but some details differ.

Are all flags covered?

Yes. All eight JavaScript flags are included — g, i, m, s, u, v, d, and y — each with a description.

Are replacement tokens included?

Yes. The replacement token section covers $&, $1, $<name>, $`, $', and $$.

Is my data sent to a server?

No. Everything runs in your browser.