HomeToolsRegexRegex Cheat Sheet

Regex Cheat Sheet

An interactive, searchable reference guide for regular expressions with inline pattern matching visualization.

Regex
Wildcard (Dot)Character Classes
.

Matches any single character except line terminators (newline).

Demo Matcher (Edit Text)/./g
cat. 9!
DigitCharacter Classes
\d

Matches any digit character (0-9). Equivalent to [0-9].

Demo Matcher (Edit Text)/\d/g
Order #4521 completed.
Non-DigitCharacter Classes
\D

Matches any character that is not a digit. Equivalent to [^0-9].

Demo Matcher (Edit Text)/\D/g
Phone: 555-1234
Word CharacterCharacter Classes
\w

Matches any alphanumeric character (letters, numbers) and underscore. Equivalent to [A-Za-z0-9_].

Demo Matcher (Edit Text)/\w/g
User_99! ID#45
Non-Word CharacterCharacter Classes
\W

Matches any character that is not a word character. Equivalent to [^A-Za-z0-9_].

Demo Matcher (Edit Text)/\W/g
User_99! ID#45
WhitespaceCharacter Classes
\s

Matches any whitespace character (spaces, tabs, newlines).

Demo Matcher (Edit Text)/\s/g
A B C D
Non-WhitespaceCharacter Classes
\S

Matches any character that is not whitespace.

Demo Matcher (Edit Text)/\S/g
A B C D
Character SetCharacter Classes
[abc]

Matches any single character listed inside the square brackets (a, b, or c).

Demo Matcher (Edit Text)/[cag]/g
the cat and the dog
Negated Character SetCharacter Classes
[^abc]

Matches any single character NOT listed inside the brackets.

Demo Matcher (Edit Text)/[^cat ]/g
cat dog
Range SetCharacter Classes
[a-z]

Matches a character within the specified range (in this case, lowercase a to z).

Demo Matcher (Edit Text)/[a-zA-Z]/g
Room 101-B
Zero or MoreQuantifiers
*

Matches the preceding token 0 or more times.

Demo Matcher (Edit Text)/ab*/g
a ab abb abbb ac
One or MoreQuantifiers
+

Matches the preceding token 1 or more times.

Demo Matcher (Edit Text)/ab+/g
a ab abb abbb ac
Zero or One (Optional)Quantifiers
?

Matches the preceding token 0 or 1 time, making it optional.

Demo Matcher (Edit Text)/colou?r/g
color and colour
Exact CountQuantifiers
{n}

Matches the preceding token exactly n times.

Demo Matcher (Edit Text)/\b\d{3}\b/g
1 12 123 1234 12345
Minimum CountQuantifiers
{n,}

Matches the preceding token n or more times.

Demo Matcher (Edit Text)/\b\d{3,}\b/g
1 12 123 1234 12345
Range CountQuantifiers
{n,m}

Matches the preceding token between n and m times.

Demo Matcher (Edit Text)/\b\d{2,4}\b/g
1 12 123 1234 12345
Start of Line / StringAnchors
^

Matches the start of the string, or the start of a line if multiline flag (m) is set.

Demo Matcher (Edit Text)/^hello/gm
hello world hello developers
End of Line / StringAnchors
$

Matches the end of the string, or the end of a line if multiline flag (m) is set.

Demo Matcher (Edit Text)/\.[a-z]+$/gm
file.txt code.ts
Word BoundaryAnchors
\b

Matches a position where a word character is adjacent to a non-word character (or start/end of string).

Demo Matcher (Edit Text)/\bcat\b/g
cat category bobcat copycat
Non-word BoundaryAnchors
\B

Matches any position that is NOT a word boundary.

Demo Matcher (Edit Text)/\Bcat\B/g
cat category bobcat copycat
Capturing GroupGroups & Captures
(abc)

Groups multiple tokens together and creates a capture group for extracting substrings.

Demo Matcher (Edit Text)/(ha)/g
ha-ha ho-ho
Non-Capturing GroupGroups & Captures
(?:abc)

Groups tokens without creating a separate capture group for extraction.

Demo Matcher (Edit Text)/(?:ha)/g
ha-ha ho-ho
Alternation (OR)Groups & Captures
a|b

Matches either the pattern on the left or the pattern on the right side of the pipe.

Demo Matcher (Edit Text)/cat|dog/g
cat dog bird
Positive LookaheadLookarounds
(?=abc)

Asserts that the given pattern matches immediately after the current position, without consuming text.

Demo Matcher (Edit Text)/\d+(?=px)/g
100px 50% 200px 80%
Negative LookaheadLookarounds
(?!abc)

Asserts that the given pattern does NOT match immediately after the current position.

Demo Matcher (Edit Text)/\b\d+(?!px)\b/g
100px 50% 200px 80%
Positive LookbehindLookarounds
(?<=abc)

Asserts that the given pattern matches immediately before the current position, without consuming text.

Demo Matcher (Edit Text)/(?<=\$)\d+/g
$100 €50 ¥200 $80
Negative LookbehindLookarounds
(?<!abc)

Asserts that the given pattern does NOT match immediately before the current position.

Demo Matcher (Edit Text)/(?<!\$)\b\d+\b/g
$100 €50 ¥200 $80

What is the Regex Cheat Sheet?

Regular expressions can be hard to memorize due to their dense, symbol-heavy syntax. This cheat sheet serves as an interactive reference for developers to quickly lookup syntax rules and immediately see how they match sample texts.

Categories Covered

  • Character Classes: Match specific types of characters (digits, letters, whitespace).
  • Quantifiers: Specify how many times a character or group should match.
  • Anchors & Boundaries: Match positions rather than characters (start/end of string, word boundaries).
  • Groups & Captures: Group characters together and create capture groups.
  • Lookarounds: Assertions that verify conditions ahead of or behind the match position without consuming characters.

How to use the Interactive Cheat Sheet

  1. Search & Filter: Search for symbols (e.g., \b or ?) or terms (e.g., “digit”, “boundary”) using the search bar, or filter by category tabs.
  2. Interactive Match Demo: Every cheat sheet card has an inline test box showing a sample string and the matched characters highlighted in real-time.
  3. Customize Sample Text: You can type directly in the sample box inside any card to see how that specific regex token matches your custom inputs.
  4. Copy Syntax: Click the copy button next to the syntax token to quickly copy it to your clipboard.

Contribute

Find a bug or want to suggest an improvement to this tool?