Regex Quick Reference
Want hands-on practice? Try the interactive Regex Tester — live matches, capture groups, and replace preview.
The 20% of regular expressions you use 95% of the time — one page, copy-paste ready.
Character classes
.any character except newline\ddigit [0-9]\Dnon-digit\wword char [A-Za-z0-9_]\Wnon-word char\swhitespace\Snon-whitespace[abc]any of a, b, c[^abc]none of a, b, c[a-z]range a–z[0-9]range 0–9\p{L}any letter (needsuflag)\p{N}any number
Quantifiers
*0 or more+1 or more?0 or 1{n}exactly n{n,}n or more{n,m}n to m*?+???lazy versions — match as few as possible
Anchors & boundaries
^start of string (or line withm)$end of string (or line withm)\bword boundary\Bnot a word boundary
Groups & lookaround
(abc)capture group(?:abc)non-capturing group(a|b)alternation\1backreference to group 1(?=abc)positive lookahead(?!abc)negative lookahead(?<=abc)positive lookbehind(?<!abc)negative lookbehind
Flags (JavaScript)
gglobal — find all matches, not just the firsticase-insensitivemmultiline —^/$match line starts/endssdotAll —.also matches newlinesuunicode — enables\p{…}, correct emoji handling
Copy-paste patterns
date YYYY-MM-DD^\d{4}-\d{2}-\d{2}$IPv4 address^(\d{1,3}\.){3}\d{1,3}$(loose — add range checks for strict) simple email^[^@\s]+@[^@\s]+\.[^@\s]+$(pragmatic, not RFC-complete) URL^https?:\/\/[^\s/$.?#].[^\s]*$Chinese mobile^1[3-9]\d{9}$trim whitespace^\s+|\s+$→ replace with empty string collapse blank lines^\s*$\nwithgm→ replace with empty string
Frequently asked questions
Why is my .* eating too much?
Quantifiers are greedy by default. Use the lazy form .*?, or better, a negated class like [^"]* when you know the delimiter.
Is there a perfect email regex?
No — the RFC grammar is enormous. The pragmatic pattern above rejects obvious junk; for real validation, send a confirmation email.
Do these work in Python / grep / VS Code?
Mostly yes — the core syntax is shared. Watch for flavor differences: lookbehind and \p{…} support vary; VS Code search uses JavaScript regex.