Regex Cheat Sheet 2026 — Patterns, Quantifiers, and Examples
Bookmark this page. Use Ctrl+F (or Cmd+F on Mac) to find what you need. This cheat sheet covers regex patterns that work in most languages (JavaScript, Python, Java, Rust, Go). Test your patterns at regex101.com. Last updated: March 2026 Basic Patterns Pattern Matches Example abc Literal text “abc” abc matches “abcdef” . Any character (except newline) a.c matches “abc”, “a1c” ^ Start of string/line ^Hello matches “Hello world” $ End of string/line world$ matches “Hello world” \ Escape special character \. matches a literal dot Character Classes Pattern Matches [abc] a, b, or c [a-z] Any lowercase letter [A-Z] Any uppercase letter [0-9] Any digit [a-zA-Z0-9] Any letter or digit [^abc] NOT a, b, or c [^0-9] NOT a digit Shorthand Classes Pattern Matches Equivalent \d Any digit [0-9] \D NOT a digit [^0-9] \w Word character [a-zA-Z0-9_] \W NOT a word character [^a-zA-Z0-9_] \s Whitespace [ \t\n\r\f] \S NOT whitespace [^ \t\n\r\f] \b Word boundary Between \w and \W \B NOT a word boundary Quantifiers Pattern Meaning Example a* 0 or more bo* matches “b”, “bo”, “boooo” a+ 1 or more bo+ matches “bo”, “boooo” (not “b”) a? 0 or 1 (optional) colou?r matches “color”, “colour” a{3} Exactly 3 \d{3} matches “123” a{2,4} 2 to 4 \d{2,4} matches “12”, “123”, “1234” a{2,} 2 or more \d{2,} matches “12”, “12345” Greedy vs Lazy Greedy (default): .* matches as MUCH as possible Lazy (add ?): .*? matches as LITTLE as possible Text: <div>hello</div><div>world</div> Greedy: <.*> matches "<div>hello</div><div>world</div>" Lazy: <.*?> matches "<div>" Groups and Capturing Pattern Description (abc) Capture group — matches “abc” and captures it (?:abc) Non-capturing group — matches but does not capture (a|b) Alternation — matches “a” OR “b” \1 Back-reference — matches same text as group 1 Pattern: (\w+)\s+\1 Text: "the the quick brown fox" Matches: "the the" (repeated word) Named Groups Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) Text: "2026-03-15" Groups: year=2026, month=03, day=15 Lookahead and Lookbehind Pattern Name Description (?=abc) Positive lookahead Followed by “abc” (?!abc) Negative lookahead NOT followed by “abc” (?<=abc) Positive lookbehind Preceded by “abc” (?<!abc) Negative lookbehind NOT preceded by “abc” Lookaround does NOT consume characters — it only checks. ...