Regular expression syntax β anchors, quantifiers, groups, lookaheads, flags, and patterns
Regex Cheat Sheet is a searchable reference for regular expression syntax covering JavaScript, Python re, and POSIX extended flavors. It organizes patterns by category β anchors, character classes, quantifiers, groups, lookarounds, and flags β so you can scan to the syntax you need rather than reading a full tutorial.
Regular expressions are one of the highest-leverage tools in a developer's toolkit, yet the syntax is dense enough that even experienced engineers keep a reference open. Forgetting whether \b matches a word boundary or backspace, or whether {2,} is greedy by default, or how to write a non-capturing group β this page answers those questions in seconds.
The sheet covers zero-width assertions like positive lookahead, negative lookbehind, named capture groups, backreferences, and the most-used flags (i, g, m, s). It also covers the differences between JavaScript and Python behavior for multiline and dotall modes.
(?: or 'lookahead'.\A) works in Python but not JavaScript.Pattern: ^\d{4}-\d{2}-\d{2}$
Result: Matches a full ISO date string like 2024-03-15 β anchors ensure no extra characters
Positive lookbehind for dollar sign
Result: Matches a dollar amount only when preceded by $, without capturing the $ character
Pattern: \b[A-Z][a-z]+(?:\s[A-Z][a-z]+)+\b
Result: Matches a proper name of two or more capitalized words like 'John Smith'
What is the difference between greedy and lazy quantifiers?
.* is greedy β matches as many characters as possible. .*? is lazy β matches as few. Use lazy quantifiers to match the shortest string between two delimiters.
How do I match a literal dot?
Escape it: \.. An unescaped dot matches any character except newline. Inside character classes like [.], the dot is literal without escaping.
What is a non-capturing group?
(?:...) groups expressions without creating a capture group. This is faster than (...) and keeps match.groups() clean.
Does JavaScript support lookbehind?
Yes, since ES2018. Positive and negative lookbehind are supported in Chrome 62+, Firefox 78+, Safari 16.4+, and Node.js 10+.
How do I make a regex case-insensitive?
Add the i flag: /pattern/i in JavaScript or re.compile('pattern', re.IGNORECASE) in Python.