Regex Cheat Sheet for Working Developers
The patterns that cover most real validation, plus the flags and greedy-vs-lazy rule that decides whether they work.
2026-10-04 · Reference
Anchors and classes
^ start, $ end, \d digit, \w word character, \s whitespace. Capitals negate them. Bracket groups match single characters, not words.
Quantifiers
*, +, ? and {n,m}. Greedy by default; add ? to make them lazy. Greedy matching causes most catastrophic backtracking.
Flags
g finds all matches, i ignores case, m makes anchors per-line, s lets . match newlines. Forgetting g is why a loop returns one match.
Why does my regex match too much?
A greedy quantifier swallowed the rest of the line — make it lazy.
How do I test safely?
Paste a real sample into the Regex Tester and check the match list first.