Skip to main content

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.

✓ Live match highlighting ✓ Named capture group display ✓ Click-to-insert cheat sheet ✓ Example patterns dropdown ✓ Runs entirely in your browser
/ /
No matches
Your test string will appear here with matches highlighted.

Regex Cheat Sheet

Click any token to insert

Character 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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →