Regex Cheatsheet

Quick reference: anchors, character classes, quantifiers, groups, lookarounds, flags. Click any pattern to copy.

Click any pattern in the table to copy it. Examples are illustrative.

Anchors, classes, quantifiers — the patterns you actually copy-paste

Regex syntax is dense and easy to half-remember. This is a quick, searchable reference for the patterns you need: anchors, character classes, quantifiers, groups, lookarounds, and flags. Rather than hunt through documentation or Stack Overflow, click any pattern to copy it straight into your editor, or use the live filter to find what you're looking for in seconds.

Lookbehinds, flags, starter patterns — six reasons to keep this open

Browse, filter, click to copy

Greedy vs lazy, flavour gaps, and the m/s flag trap

JavaScript / PCRE flavour notes

The tables group the syntax the way you actually reach for it: Anchors, Character classes, Quantifiers, Groups & alternation, Lookarounds, Flags, and a set of Common patterns. Click any pattern cell to copy it straight to your clipboard, and use the filter box to jump to a token by name — type lookahead, digit, or ?= and the sheet narrows as you go. The example column is illustrative: it shows what a token does, not a drop-in, fully-anchored validator.

The flavour is JavaScript / PCRE, and the notes column flags where they diverge so you don't copy something your engine rejects. \A and \Z (absolute string anchors) and possessive quantifiers like *+ are PCRE-only — JavaScript has neither. The free-spacing x flag is a PCRE/Python convenience, not a JS one. When a row is marked "PCRE only", assume it will silently misbehave or throw in a browser.

Lazy quantifiers, lookaround direction, and escaping for your language

How do I make a quantifier lazy instead of greedy? Append ? to it: *?, +?, ??, {2,5}?. Greedy .* grabs as much as possible then backtracks; lazy .*? grabs as little as possible — the usual fix for a pattern that "matches too much" between two delimiters.

Lookahead vs lookbehind? Lookahead asserts what follows — (?=…) positive, (?!…) negative — and lookbehind asserts what precedes — (?<=…) positive, (?<!…) negative. Both are zero-width: they test without consuming characters. Lookbehind works in modern JavaScript (ES2018+) but is absent or length-restricted in some older engines.

Why does my copied pattern not match? The examples are teaching snippets, not anchored validators — a real match usually needs your own anchors (^…$), the right flags (g, i, m, s), and correct escaping for the host language's string rules. Copy the token, then build the full expression around it.

What do the flags do? g finds all matches (not just the first), i is case-insensitive, m makes ^/$ match at line breaks, and s (dotall) lets . match newlines. They stack — /…/gim is common.