Regex Cheat Sheet
An interactive, searchable reference guide for regular expressions with inline pattern matching visualization.
Matches any single character except line terminators (newline).
/./gMatches any digit character (0-9). Equivalent to [0-9].
/\d/gMatches any character that is not a digit. Equivalent to [^0-9].
/\D/gMatches any alphanumeric character (letters, numbers) and underscore. Equivalent to [A-Za-z0-9_].
/\w/gMatches any character that is not a word character. Equivalent to [^A-Za-z0-9_].
/\W/gMatches any whitespace character (spaces, tabs, newlines).
/\s/gMatches any character that is not whitespace.
/\S/gMatches any single character listed inside the square brackets (a, b, or c).
/[cag]/gMatches any single character NOT listed inside the brackets.
/[^cat ]/gMatches a character within the specified range (in this case, lowercase a to z).
/[a-zA-Z]/gMatches the preceding token 0 or more times.
/ab*/gMatches the preceding token 1 or more times.
/ab+/gMatches the preceding token 0 or 1 time, making it optional.
/colou?r/gMatches the preceding token exactly n times.
/\b\d{3}\b/gMatches the preceding token n or more times.
/\b\d{3,}\b/gMatches the preceding token between n and m times.
/\b\d{2,4}\b/gMatches the start of the string, or the start of a line if multiline flag (m) is set.
/^hello/gmMatches the end of the string, or the end of a line if multiline flag (m) is set.
/\.[a-z]+$/gmMatches a position where a word character is adjacent to a non-word character (or start/end of string).
/\bcat\b/gMatches any position that is NOT a word boundary.
/\Bcat\B/gGroups multiple tokens together and creates a capture group for extracting substrings.
/(ha)/gGroups tokens without creating a separate capture group for extraction.
/(?:ha)/gMatches either the pattern on the left or the pattern on the right side of the pipe.
/cat|dog/gAsserts that the given pattern matches immediately after the current position, without consuming text.
/\d+(?=px)/gAsserts that the given pattern does NOT match immediately after the current position.
/\b\d+(?!px)\b/gAsserts that the given pattern matches immediately before the current position, without consuming text.
/(?<=\$)\d+/gAsserts that the given pattern does NOT match immediately before the current position.
/(?<!\$)\b\d+\b/gWhat 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
- Search & Filter: Search for symbols (e.g.,
\bor?) or terms (e.g., “digit”, “boundary”) using the search bar, or filter by category tabs. - Interactive Match Demo: Every cheat sheet card has an inline test box showing a sample string and the matched characters highlighted in real-time.
- 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.
- Copy Syntax: Click the copy button next to the syntax token to quickly copy it to your clipboard.