Regex Cheat Sheet
A compact reference for regular expression syntax that works across most flavors (JavaScript, PCRE, Python). Test patterns live with the Regex Tester.
Try it live: Regex TesterOpen Regex Tester →
Anchors
^Start of string (or line with m flag)$End of string (or line with m flag)\bWord boundary\BNot a word boundaryCharacter classes
.Any character except newline\d \DDigit / non-digit\w \WWord char [A-Za-z0-9_] / non-word\s \SWhitespace / non-whitespace[abc]Any of a, b, or c[^abc]Not a, b, or c[a-z]Range a to zQuantifiers
*0 or more+1 or more?0 or 1 (optional){n}Exactly n{n,}n or more{n,m}Between n and m*? +?Lazy (non-greedy) versionsGroups & lookarounds
(...)Capturing group(?:...)Non-capturing group(?<name>...)Named capturing groupa|bAlternation (a or b)(?=...)Positive lookahead(?!...)Negative lookahead(?<=...)Positive lookbehindFlags
gGlobal — all matchesiCase-insensitivemMultiline (^ and $ per line)sDotall (. matches newline)Common patterns
^\d+$Integer only[\w.+-]+@[\w-]+\.[\w.-]+Basic emailhttps?://[^\s]+URL^#?[0-9a-fA-F]{6}$Hex color