Regex Cheatsheet

Quick reference for regular expressions + live tester

Live Regex Tester

//

Anchors

Character Classes

Quantifiers

Groups & Lookaround

Flags / Modifiers

Common Patterns

About the Regex Cheatsheet

This regex cheatsheet lists the syntax you keep forgetting — character classes, quantifiers, anchors, groups, lookarounds and flags — each with a short example, so you can find the token you need without reading a tutorial.

A regex cheatsheet exists because regular expression syntax is dense and used intermittently. Almost nobody remembers whether a lookbehind is `(?<=` or `(?<!`, or which of `\b` and `\B` is the word boundary, and looking it up is faster than guessing.

The sections follow how patterns are actually built: character classes to say what to match, quantifiers to say how many, anchors to say where, groups to capture, and lookarounds to require context without consuming it.

Lookarounds are the entries most worth knowing. A lookahead asserts what follows without including it in the match, which is how you match a price only when followed by a currency code, or a word only when not preceded by another. For trying a pattern out, the regex tester is next door.

How to use the Regex Cheatsheet

  1. Find the section. Jump to classes, quantifiers, anchors, groups, lookarounds or flags.
  2. Read the example. Each token is shown with a short illustration of what it matches.
  3. Copy the syntax. Take the token into your pattern.
  4. Test it. Try the pattern in the regex tester against real sample text.

Regex Cheatsheet features

  • Character classes and shorthand such as \d, \w and \s
  • Quantifiers including greedy and lazy forms
  • Anchors and word boundaries
  • Capture, non-capture and named groups
  • Lookahead and lookbehind assertions
  • Flag reference for global, case-insensitive and multiline

Frequently asked questions

What is the difference between greedy and lazy quantifiers?

A greedy quantifier takes as much as it can; adding a question mark makes it lazy so it takes as little as possible.

What does \b match?

A word boundary — the zero-width position between a word character and a non-word character. \B matches the opposite.

When would I use a lookahead?

To require context without consuming it, such as matching a number only when it is followed by a currency code.

What is the difference between a capture group and (?:...)?

Both group, but (?:...) does not capture, which keeps your group numbering clean and is slightly faster.

Where can I test these patterns?

The regex tester on this site highlights matches live against sample text you provide.