Regex Syntax Reference

Searchable cheat sheet of regular-expression tokens, quantifiers and flags.

A searchable regular-expression syntax reference — character classes, anchors, quantifiers, groups, lookaround and flags — with plain-English meanings. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

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

A greedy quantifier such as * or + matches as much as possible, then backtracks. Adding a ? makes it lazy (such as *? or +?), so it matches as little as possible while still allowing the overall pattern to succeed.

A searchable cheat sheet for regular expressions — character classes, anchors, quantifiers, groups, alternation, lookaround, and flags — each with a plain-English meaning. It is handy when you are mid-pattern and just need to recall what \b, *?, or (?<=...) does without leaving your work.

How it works

The reference groups every common regex token by category — character classes, anchors, quantifiers, groups, lookaround, and flags — and shows a concise description of what each matches. Type a token or keyword such as digit, lookahead, or quantifier into the search box and the list filters instantly to the matching entries. It is purely a static lookup that follows the conventions shared by JavaScript and PCRE, so nothing is executed against your data.

Token quick-reference

Searching for digit surfaces the character-class tokens. A few of the most-used tokens:

TokenMatches
.Any character except newline
\d / \DA digit / a non-digit
\w / \WA word character / non-word character
\s / \SWhitespace / non-whitespace
^ / $Start / end of string (or line with m)
\bWord boundary
* + ?0+, 1+, 0 or 1 (add ? for lazy)
{n,m}Between n and m repetitions
(?=...) / (?!...)Positive / negative lookahead
(?<=...) / (?<!...)Positive / negative lookbehind

Common patterns explained

Greedy vs lazy quantifiers — this is where most regex bugs hide. ".*" is greedy: given the string "foo" and "bar", it matches the entire span from the first " to the last ", consuming both quoted strings. Switch to ".*?" and the lazy ? makes it stop at the first closing quote, matching only "foo". When you are extracting delimited values, lazy is almost always what you want.

Word boundaries\b is a zero-width assertion that matches the transition between a word character (\w) and a non-word character. It lets you find cat as a whole word without accidentally matching category or concatenate. Because \b matches a position rather than a character, it never appears in the captured text.

Flags change how the whole pattern behaves. The most important ones:

FlagEffect
gFind all matches, not just the first
iCase-insensitive matching
m^ and $ match line boundaries, not just string boundaries
sDotall — . matches newlines too
uEnable full Unicode support

Lookaround quick guide

Lookahead and lookbehind let you assert what surrounds a match without consuming it — they are invisible fence-posts, not actual characters in the match.

  • (?=price) — positive lookahead: match only if what follows is price
  • (?!draft) — negative lookahead: match only if what follows is not draft
  • (?<=\$) — positive lookbehind: match only if $ immediately precedes
  • (?<!un) — negative lookbehind: match only if un does not immediately precede

A typical use: \d+(?= items?) captures a count only when the word “item” or “items” follows it, without including that word in the match.

When regex is the wrong tool

Regex is excellent for pattern matching in strings, but it is the wrong tool for deeply nested structures. Parsing HTML, XML or JSON with a single regex is fragile — use a proper parser for those. Similarly, regex has no memory of what it matched earlier in the same string unless you use backreferences (\1, \2), which become hard to read fast. For complex grammars, consider a parser combinator library instead.

Everything runs in your browser; nothing is uploaded.