Regex Tools

Regex Cheatsheet: Complete Regular Expression Quick Reference Guide

A complete, searchable regex cheatsheet covering anchors, quantifiers, character classes, groups, lookaheads, and flags with live examples.

Published January 15, 2025Updated June 1, 20256 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

Regular expression syntax is remarkably compact — a dozen or so special characters can express patterns that would take hundreds of lines of imperative code to replicate. The downside of that compactness is that the syntax is dense and non-obvious, making a reliable reference guide essential even for developers who use regex regularly. A well-organized cheatsheet turns a frustrating lookup into a quick scan.

This cheatsheet covers the full regex syntax used in JavaScript, with notes on compatibility with Python, PCRE, and Java. Every entry includes the syntax token, a plain-English description of what it matches, and a live clickable example that loads the pattern directly in the tester so you can experiment immediately. Categories are clearly divided: anchors, character classes, quantifiers, groups and alternation, lookarounds, and flags.

Bookmark this page as your go-to regex reference. Whether you are trying to remember whether \w includes digits (it does) or which quantifier is lazy by default (none — you add ? to make them lazy), the answer is a quick scroll away.

What Is a Regex Cheatsheet?

A regex cheatsheet is a concise reference card that lists all regular expression syntax tokens with their meanings and brief examples. Rather than reading through a full tutorial, you scan the cheatsheet to find the specific token or construct you cannot remember, confirm its behavior, and move on.

The best cheatsheets are organized by conceptual category rather than alphabetically. Grouping anchors together, then character classes, then quantifiers, then groups and lookarounds lets you find what you need based on what you are trying to do, not what letter it starts with.

This cheatsheet is interactive: every example pattern is clickable and opens in the regex tester with a sample string pre-loaded. That means you are never more than one click away from a live demonstration of any syntax token.

How to Use This Tool

Navigate the cheatsheet efficiently with these steps:

  1. 1

    Use the Search Bar

    Type a keyword like 'word boundary', 'lookahead', or 'quantifier' into the search bar to instantly filter the cheatsheet to relevant entries.

  2. 2

    Browse by Category

    Use the category tabs — Anchors, Character Classes, Quantifiers, Groups, Lookarounds, Flags — to jump to the section you need without scrolling.

  3. 3

    Click Any Example

    Click the example pattern next to any entry to open it in the live tester with a sample test string pre-loaded, so you can see the token in action immediately.

  4. 4

    Copy a Token

    Hover over any syntax entry to reveal a copy button. Click it to copy just the token or the full example pattern to your clipboard.

  5. 5

    Switch Language Mode

    Use the language toggle to switch between JavaScript, Python, and PCRE views. Entries that differ between flavors are highlighted, and the example syntax updates accordingly.

Common Use Cases

Developers reach for a regex cheatsheet in many day-to-day situations:

  • Quickly confirming which anchor to use (^ vs \A, $ vs \Z) when porting a pattern between JavaScript and Python
  • Looking up the correct syntax for a non-capturing group (?:...) to avoid polluting match results with unwanted group captures
  • Remembering the Unicode property escape syntax \p{L} when writing patterns that must match letters across multiple scripts
  • Finding the right quantifier variant — greedy, lazy, or possessive — when debugging a pattern that is consuming too much or too little input
  • Checking lookaround syntax (positive vs negative, ahead vs behind) when writing patterns that must match based on surrounding context without consuming those characters

Tips and Best Practices

Use this cheatsheet as a learning tool as well as a reference by applying these habits:

  • When you look up a token, take 30 seconds to click its example and modify the test string — active interaction builds memory far better than passive reading
  • Pay special attention to the difference between similar-looking tokens: \d vs \D, \w vs \W, \s vs \S — the uppercase variants are always the complement of the lowercase
  • Remember that quantifiers are greedy by default; adding ? after any quantifier (like *? or +?) makes it lazy, which is often what you actually want inside a larger pattern
  • Lookaheads and lookbehinds are zero-width — they assert a condition without consuming characters, which is crucial to understand when building patterns that need to match adjacent items
  • Keep the cheatsheet open in a browser tab while you write regex; it is faster to glance at it than to break your concentration searching a documentation site

Frequently Asked Questions

What is the difference between a character class and a group?

A character class, written with square brackets like [aeiou], matches a single character that is any one of the listed characters. A group, written with parentheses like (cat|dog), matches the entire sub-expression and can capture its match for later use. They serve fundamentally different purposes.

What does the \b anchor do?

\b matches a word boundary — a position between a word character (\w) and a non-word character (\W), including the start and end of the string. It does not consume any characters. Use \b to match whole words: \bcat\b matches 'cat' but not 'concatenate'.

When should I use a non-capturing group (?:...)?

Use a non-capturing group when you need to group part of a pattern for alternation or quantification but do not need to reference that part later. Non-capturing groups are slightly more efficient and keep your group numbering cleaner when you do have capturing groups you want to reference.

What is the difference between a greedy and a lazy quantifier?

A greedy quantifier like * or + matches as many characters as possible while still allowing the overall pattern to succeed. A lazy quantifier like *? or +? matches as few characters as possible. Lazy quantifiers are essential when you want to match the smallest possible token, for example the content between two tags.

How does a positive lookahead differ from a positive lookbehind?

A positive lookahead (?=...) asserts that the pattern inside follows the current position. A positive lookbehind (?<=...) asserts that the pattern inside precedes the current position. Both are zero-width assertions — they influence what matches without being part of the match itself.

Does \w match Unicode letters?

In JavaScript's default mode, \w matches only ASCII word characters [A-Za-z0-9_]. To match Unicode letters, use the u flag combined with \p{L} for Unicode letter properties. Python's re module matches Unicode letters with \w by default unless the ASCII flag is passed.

What does the s (dotAll) flag do?

By default, the dot . in a regex matches any character except a newline. The dotAll flag (s) changes this so . also matches newline characters. This is useful when your target text spans multiple lines and you want . to traverse line breaks.

Are there regex tokens that differ significantly between JavaScript and Python?

Yes. Named group syntax differs: JavaScript uses (?<name>...) while Python uses (?P<name>...). Lookbehind in JavaScript requires fixed-length patterns in some engines. Python supports atomic groups and possessive quantifiers via the regex library but not the built-in re module. The cheatsheet highlights these differences per entry.

regex cheatsheetregular expressionsregex syntaxregex referencepattern matchingcheatsheet

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More Regex Tools Guides