Regex Cheat Sheet & Live Tester
Test patterns against real input with live match highlighting, then click any cheat sheet token to insert it directly into your regex.
Regex Cheat Sheet
Click any token to insertCharacter Classes
Anchors
Quantifiers
Groups & References
Lookahead / Lookbehind
Flags
Special Characters
Frequently Asked Questions
What does the 'g' flag do in regex?▼
The 'g' (global) flag makes the regex find all matches in a string, not just the first one. Without 'g', methods like match() stop after the first match. With 'g', exec() advances through all matches and match() returns an array of all matches.
What is catastrophic backtracking and how do I avoid it?▼
Catastrophic backtracking occurs when a regex engine explores an exponential number of possible paths before determining no match exists. It's common with nested quantifiers like (a+)+. Avoid it by using atomic groups, possessive quantifiers (in supported engines), or rewriting the pattern to remove ambiguity — for example, replacing overlapping alternatives with more specific patterns.
What's the difference between \d and [0-9]?▼
In most engines \d matches any Unicode decimal digit, while [0-9] matches only ASCII digits 0 through 9. In JavaScript with the 'u' flag, \d still matches only [0-9]. If you want strict ASCII digits, [0-9] is clearer and slightly more predictable across engines.
How do lookaheads and lookbehinds work?▼
Lookaheads (?=...) and (?!...) assert that a pattern does or doesn't follow the current position without consuming characters. Lookbehinds (?<=...) and (?<!...) do the same for what precedes. For example, \d+(?= dollars) matches a number only when followed by ' dollars', without including ' dollars' in the match.
Why does my regex work in one language but not another?▼
Regex flavors differ across languages. JavaScript lacks lookbehind in older engines, doesn't support named backreferences in replace in all versions, and has different Unicode handling. Python's 're' module supports possessive quantifiers only via the 'regex' package. Always test your pattern in the target language's environment.
How do I match a literal dot or other special characters?▼
Escape special characters with a backslash: \. matches a literal dot, \* matches a literal asterisk, \( matches a literal parenthesis. The special characters that need escaping are: . * + ? ^ $ { } [ ] | ( ) \ /. Inside a character class [ ], only ] \ ^ - need escaping.
Related Products
on GumroadDeveloper Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
Regex Tester Pro
Free Regex Tester Pro with real-time match highlighting. Test regular expressions with live visual feedback. Supports JS, Python, and Ruby flavors, all flags, capture groups, and 6 built-in presets. R
Open free tool →
Regex Tester
Free regex tester. Test regular expressions against multiple strings with expected match/no-match assertions — see instant pass/fail results. Built-in presets for email, URL, IPv4, and phone. Pro: unl
Open free tool →
AI Regex Explainer — Pro Tool
Paste any regular expression and get a plain-English breakdown, match examples, and gotchas. Explains capture groups, lookaheads, and common mistakes. Free regex explainer tool. DevPlaybook Pro featur
Open free tool →
More Free Tools
Related Articles
Regex Cheat Sheet: Complete Guide for Developers
The complete regex cheat sheet for developers in 2026. Master syntax, quantifiers, groups, lookaheads, and 30+ ready-to-use patterns for validation, parsing, and text transformation.
Best Free Regex Testers for Web Developers
The best free online regex testers for web developers in 2025. Compare features, language support, and find the right regex testing tool for your workflow.
Pydantic v2 Complete Guide: Validation, Settings & Data Modeling
Master Pydantic v2 in 2025. BaseModel validation, field validators, model settings, custom types, serialization, and performance improvements over v1 with code examples.
Test-Driven Development Guide 2026: Practical TDD That Actually Works
Learn TDD the practical way in 2026. Red-green-refactor workflow, real-world examples in JavaScript and Python, when TDD helps vs hurts, and how to introduce it to your team.
Zod 4: The Ultimate TypeScript Schema Validation Guide (2026)
Complete guide to Zod 4 with breaking changes from v3, new .transform/.pipe API, coercion improvements, discriminated unions, tree-shaking, and comparison with Valibot and ArkType.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →