Fantastic IT Tools
Web & Dev

Regex Cheatsheet

Searchable reference of regex tokens, quantifiers, groups and lookarounds.

43 results
^
Anchors

Start of string (or line with m flag).

^abc matches "abc" at start

$
Anchors

End of string (or line with m flag).

abc$ matches "abc" at end

\b
Anchors

Word boundary.

\bcat\b matches "cat" not "category"

\B
Anchors

Non-word boundary.

\Bcat matches "cat" in "bobcat"

.
Character classes

Any character except newline.

a.c matches "abc", "axc"

[abc]
Character classes

Any one of a, b or c.

[aeiou] matches a vowel

[^abc]
Character classes

Any character except a, b or c.

[^0-9] matches a non-digit

[a-z]
Character classes

Character range.

[a-z] matches one lowercase letter

\d
Character classes

Any digit (0-9).

\d{4} matches "2026"

\D
Character classes

Any non-digit.

\D matches "a"

\w
Character classes

Word character [A-Za-z0-9_].

\w+ matches "user_1"

\W
Character classes

Non-word character.

\W matches "!"

\s
Character classes

Whitespace (space, tab, newline).

a\sb matches "a b"

\S
Character classes

Non-whitespace.

\S+ matches a word

*
Quantifiers

Zero or more (greedy).

ab* matches "a", "ab", "abb"

+
Quantifiers

One or more (greedy).

a+ matches "a", "aaa"

?
Quantifiers

Zero or one (optional).

colou?r matches "color"/"colour"

{n}
Quantifiers

Exactly n times.

\d{3} matches "123"

{n,}
Quantifiers

n or more times.

\d{2,} matches "12", "1234"

{n,m}
Quantifiers

Between n and m times.

\d{2,4} matches "12" to "1234"

*?
Quantifiers

Lazy (non-greedy) zero or more.

<.*?> matches one tag at a time

+?
Quantifiers

Lazy one or more.

a+? matches as few "a" as possible

(abc)
Groups

Capturing group.

(ab)+ captures "ab"

(?:abc)
Groups

Non-capturing group.

(?:ab)+ groups without capturing

(?<name>abc)
Groups

Named capturing group.

(?<year>\d{4})

a|b
Groups

Alternation (a or b).

cat|dog matches either word

\1
Groups

Backreference to group 1.

(\w)\1 matches doubled letters

\k<name>
Groups

Backreference to a named group.

(?<q>["']).*?\k<q>

(?=abc)
Lookaround

Positive lookahead.

\d(?=px) matches digit before "px"

(?!abc)
Lookaround

Negative lookahead.

\d(?!px) digit not before "px"

(?<=abc)
Lookaround

Positive lookbehind.

(?<=\$)\d+ matches digits after "$"

(?<!abc)
Lookaround

Negative lookbehind.

(?<!\$)\d+ digits not after "$"

\.
Escapes

Literal dot (escaped metachar).

example\.com

\/
Escapes

Literal forward slash.

https?:\/\/

\n
Escapes

Newline character.

line1\nline2

\t
Escapes

Tab character.

col1\tcol2

\\
Escapes

Literal backslash.

C:\\Windows

g
Flags

Global — find all matches, not just the first.

/a/g

i
Flags

Case-insensitive matching.

/abc/i matches "ABC"

m
Flags

Multiline — ^ and $ match line boundaries.

/^a/m

s
Flags

Dotall — . also matches newlines.

/a.b/s

u
Flags

Unicode mode.

/\u{1F600}/u

y
Flags

Sticky — match at lastIndex only.

/a/y