Regex Quick Reference
Regular expression syntax, flags, and common patterns with examples.
Character Classes
. Any character except newline \d Any digit (0-9) \D Any non-digit \w Word character (a-z, A-Z, 0-9, _) \W Non-word character \s Whitespace (space, tab, newline) \S Non-whitespace character [abc] Any of a, b, or c [^abc] Not a, b, or c [a-z] Character range (a to z) Quantifiers
* Zero or more times + One or more times ? Zero or one time (optional) {n} Exactly n times {n,} n or more times {n,m} Between n and m times *? Zero or more (lazy) +? One or more (lazy) Anchors
^ Start of string (or line with m flag) $ End of string (or line with m flag) \b Word boundary \B Non-word boundary Groups & Lookaround
(abc) Capturing group (?:abc) Non-capturing group (?<name>abc) Named capturing group \1 Backreference to group 1 (?=abc) Positive lookahead (?!abc) Negative lookahead (?<=abc) Positive lookbehind (?<!abc) Negative lookbehind a|b Alternation (a or b) Flags
g Global: find all matches i Case-insensitive matching m Multiline: ^ and $ match line boundaries s Dotall: . matches newline too u Unicode: enable Unicode features Common Patterns
Email Basic email validation URL HTTP/HTTPS URL Phone (US) US phone number IPv4 IP address v4 Date (ISO) YYYY-MM-DD format Hex Color #RGB or #RRGGBB HTML Tag Match HTML tags Slug URL-friendly slug