RegEx Cheatsheet

A complete quick reference for regular expression syntax. Organized into six categories: anchors, character classes, quantifiers, groups & references, lookaround, and flags - each token shown with its description and a practical example. Search to filter by any term.

FAQ

The cheatsheet covers six categories: Anchors (^, $, \b), Character Classes (\d, \w, \s, [abc], .), Quantifiers (*, +, ?, {n,m}, lazy variants), Groups & References (capturing, non-capturing, named, backreferences, alternation), Lookaround (positive/negative lookahead and lookbehind), and Flags (g, i, m, s, u).

The syntax shown works with JavaScript/ECMAScript regex, which is also compatible with most modern languages (Python, Java, C#, Ruby). Lookbehind assertions may not be supported in older Safari versions - check caniuse.com for browser compatibility.

By default, . (dot) doesn't match newlines. Enable the 's' (dotall) flag to make . match everything including newlines. Without dotall, use [\s\S] or [\d\D] as workarounds to match any character including line breaks. The 'm' (multiline) flag makes ^ and $ match the start/end of each line instead of just the whole string.

\b (word boundary) matches at positions between a word character (\w) and a non-word character or the start/end of a string. Use it to match whole words: \bcat\b matches 'cat' but not 'catch'. \B (non-word boundary) matches everywhere \b doesn't — inside words or between non-word characters.

Backreferences allow matching the same text captured earlier in the pattern. \1 refers to the first capturing group, \2 to the second, etc. For example, (\w+)\s+\1 matches repeated words like 'the the'. Named capture groups (?...) can be referenced with \k in some regex flavors.

Use this cheatsheet as a syntax reference while you write patterns in the RegEx Tester tool. Look up a token here, then switch to the tester to build and test your regex against real data with live match highlighting.