Regex Cheatsheet
Quick reference for regular expression syntax — character classes, quantifiers, anchors, groups, lookaheads, and common real-world patterns.
Character Classes
.\d\D\w\W\s\S[abc][^abc][a-z][A-Z0-9]Anchors
^$\b\BQuantifiers
*+?{n}{n,}{n,m}*?+?Groups & References
(abc)(?:abc)(?<name>abc)\1(a|b)Lookahead & Lookbehind
(?=abc)(?!abc)(?<=abc)(?<!abc)Flags
gimsuCommon Patterns
^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$^https?://[^\s]+$^\d{1,3}(\.\d{1,3}){3}$^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$^\d{4}-\d{2}-\d{2}$^\+?[\d\s-]{7,15}$^(?=.*[A-Z])(?=.*\d).{8,}$FAQ
What is the difference between * and + in regex?
* matches 0 or more occurrences (the preceding element is optional), while + matches 1 or more (at least one occurrence is required). For example, ab*c matches 'ac' and 'abc', but ab+c only matches 'abc' (not 'ac').
What is a non-greedy (lazy) quantifier?
By default, quantifiers like * and + are greedy — they match as much as possible. Adding ? makes them lazy, matching as little as possible. For example, on '<b>bold</b>', <.*> matches the entire string (greedy), while <.*?> matches just '<b>' (lazy).
How do I match a literal dot or bracket in regex?
Escape special characters with a backslash: \. matches a literal dot, \[ matches a literal bracket, and \\ matches a literal backslash. Inside a character class [.], the dot is already literal.
What is a lookahead in regex?
A lookahead checks if a pattern exists ahead of the current position without consuming characters. (?=abc) is a positive lookahead (succeeds if abc follows), and (?!abc) is a negative lookahead (succeeds if abc does NOT follow). They're useful for validating conditions like passwords.