Skip to content
Appachi Tools

Regex Cheat Sheet

Every regex token you actually use, grouped by category, with a plain-English meaning and a real example — search to find the one you half-remember.

Try any of these live in the Regex Tester →

Character classes

.

Any character except newline

a.c matches "abc", "a c"

\d

A digit (0-9)

\d{3} matches "123"

\D

Any non-digit

\D+ matches "abc" in "abc123"

\w

A word character (letters, digits, underscore)

\w+ matches "hello_1"

\W

Any non-word character

\W matches " ", "-", "!"

\s

Any whitespace (space, tab, newline)

a\sb matches "a b"

\S

Any non-whitespace character

\S+ matches "hello"

[abc]

Any one of the listed characters

[aeiou] matches any vowel

[^abc]

Any character NOT listed

[^0-9] matches any non-digit

[a-z]

Any character in the range

[a-zA-Z] matches any letter

Quantifiers

*

Zero or more of the preceding token

ab*c matches "ac", "abc", "abbbc"

+

One or more of the preceding token

ab+c matches "abc" but not "ac"

?

Zero or one of the preceding token (optional)

colou?r matches "color" and "colour"

{n}

Exactly n occurrences

\d{4} matches a 4-digit number

{n,}

n or more occurrences

\d{2,} matches 2+ digits

{n,m}

Between n and m occurrences

\d{2,4} matches 2 to 4 digits

*? +? ??

Lazy (non-greedy) versions — match as little as possible

<.+?> on "<a><b>" matches "<a>" only

Anchors & boundaries

^

Start of the string (or line, with the m flag)

^Hello matches "Hello world" only at the start

$

End of the string (or line, with the m flag)

world$ matches "hello world" only at the end

\b

A word boundary

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

\B

NOT a word boundary

\Bcat matches "concat" but not "cat"

Groups & alternation

(...)

A capturing group — matched text is extractable

(\d{4})-(\d{2}) captures year and month

(?:...)

A non-capturing group — groups without capturing

(?:abc)+ groups "abc" for repetition only

(?<name>...)

A named capturing group

(?<year>\d{4}) captures as "year"

|

Alternation — matches either side

cat|dog matches "cat" or "dog"

\1

A backreference to capture group 1

(\w)\1 matches any doubled letter, e.g. "ss"

Lookaround

(?=...)

Lookahead — matches if followed by this pattern (not included in the match)

\d+(?=px) matches "10" in "10px"

(?!...)

Negative lookahead — matches if NOT followed by this pattern

\d+(?!px) matches "10" in "10em" but not in "10px"

(?<=...)

Lookbehind — matches if preceded by this pattern

(?<=\$)\d+ matches "10" in "$10"

(?<!...)

Negative lookbehind — matches if NOT preceded by this pattern

(?<!\$)\d+ matches "10" in "10 items" but not "$10"

Flags

g

Global — find all matches, not just the first

i

Case-insensitive matching

m

Multiline — ^ and $ match the start/end of each line

s

Dot-all — . also matches newlines

u

Unicode — enables full Unicode pattern support

y

Sticky — matches only starting at lastIndex

About the Regex Cheat Sheet

Regex syntax is dense by design — a handful of symbols cover an enormous range of matching logic, which is exactly why it's so easy to half-remember. This reference groups tokens the way you actually think about them while writing a pattern: what am I matching, how many of it, and where.

Most of what's here is shared across regex engines (JavaScript, Python, PCRE), but a few features — like lookbehind and named capture groups — have historically had inconsistent support, so it's worth confirming a given token works in your specific engine, especially for regex targeting older environments.

How to use it

  1. 1Search for what you're trying to do, e.g. "digit" or "lookahead".
  2. 2Read the symbol, its meaning, and an example.
  3. 3Jump to the Regex Tester to try it against real text.

Features

  • Character classes, quantifiers, anchors, groups and lookaround
  • Every entry paired with a real example, not just the symbol
  • Instant search across symbols and descriptions
  • One click through to the Regex Tester to try any pattern live

Frequently asked questions

What is the difference between * and +?

* matches zero or more of the preceding token (so it can match nothing); + requires at least one occurrence.

What does (?:...) mean?

It's a non-capturing group — it groups a pattern for alternation or quantifying without creating a numbered capture group in the results, useful when you need grouping but don't need to extract that part.

What is the difference between lookahead and lookbehind?

Both check for a pattern without including it in the match. Lookahead (?=...) checks what follows the current position; lookbehind (?<=...) checks what precedes it.

Where can I test a pattern from here?

Every entry links to the Regex Tester, where you can try it against real text with live match highlighting.

From the blog

Related tools