Regex Cheatsheet
Every regex token, one search away.
Anchors
^^hello$world$\b\bcat\b\B\BcatCharacter classes
.a.c\d\d+\D\D+\w\w+\W\W+\s\s+\S\S+[abc][aeiou][^abc][^0-9][a-z][A-Za-z]Quantifiers
*a*+a+?colou?r{n}\d{4}{n,}\d{2,}{n,m}\d{2,4}*?a*?+?<.+?>Groups & lookarounds
(abc)(\d+)(?:abc)(?:ab)+(?<name>x)(?<year>\d{4})\1(\w)\1(?=x)\d(?=px)(?!x)\d(?!px)(?<=x)(?<=%)\d+(?<!x)(?<!\$)\d+Escapes
\.example\.com\\C:\\\(\(x\)\n\n\t\t\r\rCommon patterns
email[\w.+-]+@[\w-]+\.[a-z]{2,}urlhttps?://[\w.-]+(?:/[\w./?=-]*)?ipv4(?:\d{1,3}\.){3}\d{1,3}hex color#(?:[0-9a-f]{3}){1,2}date\d{4}-\d{2}-\d{2}phone\(?\d{3}\)?[-.\s]?\d{3}[-.]\d{4}How to use the Regex Cheatsheet
Regular expressions have a notoriously dense syntax that is hard to keep in your head. This is a searchable quick-reference of the tokens that work across JavaScript, Python, Go and PCRE — anchors, character classes, quantifiers, groups, lookarounds and a handful of ready-made patterns for common jobs.
- 01Start typing in the search box — the table filters live across tokens, names and descriptions.
- 02Browse the sections (Anchors, Character classes, Quantifiers, Groups, Escapes, Common patterns) to jog your memory.
- 03Click the copy button on the right of any example to grab a working pattern, then paste it into the Regex Tester to try it on real text.
tips
- —Most regex bugs come from greedy quantifiers eating too much. Add a
?after*or+to make them lazy:<.+?>matches a single tag instead of the whole document. - —JavaScript supports named groups (
(?<year>\d4)) and lookbehind ((?<=…)) since ES2018. Older browsers (IE, old Safari) reject them — compile to a fallback if you need to support them. - —For emails, URLs and HTML, prefer a permissive regex and validate server-side. A regex that accepts every valid email rejects almost nothing useful; a strict one blocks real addresses.
[\w.+-]+@[\w-]+\.[a-z]{2,}is the sweet spot for client-side hints.
frequently asked
Which regex flavor does this cover?+
The reference targets the syntax shared by JavaScript, Python, Go, Java, Rust and PCRE — anchors, character classes, quantifiers, groups and lookarounds. Engine-specific extensions like possessive quantifiers or atomic groups are noted where they differ.
Why does my regex work on regex101 but not in JS?+
JavaScript supports lookaheads but historically not lookbehinds (until ES2018). Python uses (?P<name>) for named groups, JS uses (?<name>). The cheatsheet calls out these dialect differences inline.
Can I test a pattern against text here?+
The cheatsheet is a reference, not a tester. For live matching, hop over to the Regex Tester tool — paste a pattern and sample text to see captures and matches highlighted.