Regex Cheat Sheet: Essential Patterns for Developers
2026-05-24
Quick Answer
Quick Answer: Start with anchors ^ and $, use character classes like \d and \w, and test interactively in our Regex Tester. Patterns below cover 80% of day-to-day tasks.
Anchors and quantifiers
| Pattern | Meaning |
|---|---|
^ | Start of string (or line with m) |
$ | End of string |
* | 0 or more |
+ | 1 or more |
? | 0 or 1 |
{n,m} | Between n and m |
Patterns you'll use weekly
Email (simple)
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
URL
https?:\/\/[\w\-]+(\.[\w\-]+)+[/#?]?.*
Date ISO (YYYY-MM-DD)
\d{4}-\d{2}-\d{2}
UUID
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
Paste any pattern into the Regex Tester and toggle flags (i case-insensitive, g global).
Flags that matter
i— case insensitive matchingg— find all matches, not just the firstm—^and$match line boundaries
Pitfall: catastrophic backtracking
Nested quantifiers like (a+)+ on long strings can freeze the browser. Prefer specific character classes and test on small samples first.
Try It Yourself
Frequently Asked Questions
What is the difference between . and \.?
. matches any character (except newline). \. matches a literal dot.
Do I need to escape slashes in JavaScript regex?
In /pattern/ literals, forward slashes must be escaped. In new RegExp("pattern") strings, escape backslashes: "\\d+".
When should I avoid regex?
Parsing HTML, JSON, or nested structures with regex alone—use a proper parser instead.