Regex Cheat Sheet
Searchable regular expression reference with examples, language notes, and links to try each pattern live.
Quick Reference
Characters
Quantifiers
Anchors
Groups & References
Lookaround
Character Classes
Flags
| Pattern | Description | |
|---|---|---|
g | Global - match all occurrences JS, Python (re.findall). Go matches all by default | Try it |
i | Case-insensitive All. Python: re.IGNORECASE. Go: (?i) | Try it |
m | Multiline - ^ and $ match line boundaries All. Python: re.MULTILINE. Go: (?m) | Try it |
s | Dotall - dot matches newline JS (ES2018+), Python (re.DOTALL), Java. Go: (?s) | Try it |
u | Unicode support JS, Python (default in 3.x), Java. Go is UTF-8 native | Try it |
Common Patterns
| Pattern | Description | |
|---|---|---|
^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$ | Email address (basic) | Try it |
^https?://[\w.-]+(?:/[\w./-]*)?$ | URL (basic HTTP/HTTPS) | Try it |
^\d{1,3}(\.\d{1,3}){3}$ | IPv4 address (basic) | Try it |
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ | Hex color code | Try it |
^\d{4}-\d{2}-\d{2}$ | Date (YYYY-MM-DD) | Try it |
^\+?[1-9]\d{1,14}$ | Phone number (E.164) | Try it |
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$ | Strong password (8+, upper, lower, digit) | Try it |
^-?\d+(\.\d+)?$ | Number (integer or decimal) | Try it |
Language-Specific Notes
JavaScript
- Regex literals:
/pattern/flags - Named groups:
(?<name>...) - Lookbehind supported since ES2018
\p{L}Unicode withuflagdflag for indices (ES2022)
Python
- Use
r"raw strings"for patterns - Named groups:
(?P<name>...) - Flags:
re.IGNORECASE,re.MULTILINE,re.DOTALL re.findall()returns all matches- Verbose mode:
re.VERBOSEfor commented patterns
Go
- Uses RE2 syntax (no backtracking)
- No lookbehind support
- Named groups:
(?P<name>...) - Inline flags:
(?i),(?m),(?s) - Use backticks for raw strings:
`\d+`
Java
- Double-escape in strings:
"\\d+" - Named groups:
(?<name>...) - Flags via
Pattern.compile(pattern, flags) - Possessive quantifiers:
*+,++ - Atomic groups:
(?>...)
What is a Regex Cheat Sheet?
A regex cheat sheet is a quick reference for regular expression syntax — character classes, quantifiers, anchors, groups, lookaheads, and flags. Regex syntax is powerful but dense, and even experienced developers need to look up less common features. This reference covers JavaScript regex syntax with examples and descriptions for every pattern type.
Common Use Cases
- •Quickly referencing regex syntax while writing patterns
- •Looking up quantifiers, character classes, and assertions
- •Finding the correct syntax for lookahead/lookbehind
- •Understanding regex flags (global, multiline, unicode)
- •Learning regex systematically from basics to advanced
Frequently Asked Questions
What is a lookahead in regex?
A lookahead checks if a pattern exists ahead of the current position without consuming characters. Positive lookahead (?=...) matches if the pattern exists; negative lookahead (?!...) matches if it doesn't. Example: \d+(?=px) matches numbers followed by 'px' but doesn't include 'px' in the match.
What regex flags should I know?
The most important: g (global — match all, not just first), i (case-insensitive), m (multiline — ^ and $ match line start/end), s (dotAll — . matches newlines), and u (unicode — correct handling of Unicode characters).