Regex Cheatsheet

Look up regex syntax fast. Search or browse anchors, character classes, quantifiers, groups, lookarounds, flags and escapes — each with a plain-English meaning and an example — and open any example in the Regex Tester with one click to see it match. Every example is tested to work. It's free and runs in your browser.

The essentials

TokenMeans
^ $Start / end
\d \w \sDigit, word character, whitespace
* + ? {n,m}Quantifiers
( ) (?: ) (?<n> )Groups
(?= ) (?! ) (?<= ) (?<! )Lookarounds
g i m s u yFlags

When to use it

  1. Remember the syntax for a lookbehind or named group.
  2. Check the difference between greedy and lazy quantifiers.
  3. Find the right flag for multiline matching.
  4. Learn regular expressions with examples you can run.

How to Use

  1. Search for a token or concept, or jump to a category.
  2. Read the meaning and example.
  3. Click Try it to run the example in the Regex Tester.

Features

  1. Seven categories, 37 entries
  2. Search across tokens and meanings
  3. Every example tested to match
  4. One-click Try it in the Regex Tester
  5. Flavor notes

FAQs

What's the difference between * and *?

* is greedy and matches as much as possible; *? is lazy and stops at the first chance. <.+?> matches one tag; <.+> would swallow everything to the last >.

How do I match a whole word?

Wrap it in word boundaries: \bcat\b matches cat but not concat.

Do lookbehinds work in JavaScript?

Yes, in all current browsers. Safari added them in version 16.4, so very old Safari lacks them.

Is this the same in Python or PCRE?

Mostly. Named groups are (?P<name>…) in older Python, and flags are set differently, but anchors, classes, quantifiers and lookarounds behave the same.

Can I try an example?

Yes — Try it opens the Regex Tester with the pattern and sample filled in.

Technical Details

The cheatsheet covers the syntax used every day — anchors and word boundaries, character classes including Unicode property escapes, greedy and lazy quantifiers, capturing, non-capturing and named groups with back-references, alternation, the four lookarounds, every JavaScript flag, and character escapes — each with a one-line meaning, an example pattern and a sample string. Every example is part of the site's automated tests: each pattern is compiled with its flags and checked to match its own sample, so the reference can't drift into examples that don't work. Search filters across tokens, meanings and examples. The Try it link opens the Regex Tester with the pattern, flags and sample already filled in, so you can edit them and watch the matches change. Examples use JavaScript syntax, and the page notes where other engines differ, such as \p{…} needing the u flag and lookbehind being missing from some older engines.

Developer Tools

Developer Tools

  • JSON to GraphQL
  • Regex Escape & Extract
  • AI Prompt Generator
  • Combine Files for AI
  • Freelance Rate Calculator
  • H-1B Wage Level Worksheet
  • Keyboard Tester
  • localStorage Viewer