Regex has a reputation for being unreadable. ^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])? is technically a partial email validator. It's also a headache.
But regex doesn't have to be cryptic. With a few key patterns and a good testing tool, it becomes a precise and powerful part of your toolkit.
The five most useful everyday patterns
1. Match a simple email address
Regex
/^[^\s@]+@[^\s@]+\.[^\s@]+$/
// Matches: [email protected], [email protected]
// Doesn't match: @nodomain.com, noemail
2. Extract all URLs from text
Regex
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&/=]*)/g
3. Match a hex colour
Regex
/#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/g
// Matches: #ff6b6b, #FFF, #9d92ff
4. Validate a slug (URL-safe string)
Regex
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
// Matches: my-post-title, hello-world-2025
// Doesn't match: My Post, --invalid, trailing-
5. Strip HTML tags
Regex
/<[^>]*>/g
// Replace with '' to remove all HTML tags from a string
Flags cheat sheet
| Flag | Meaning | Example |
|---|---|---|
g | Global — find all matches, not just the first | /\d+/g |
i | Case-insensitive | /hello/i |
m | Multiline — ^ and $ match line boundaries | /^start/m |
s | Dotall — . matches newlines too | /a.b/s |
Test as you write. Never write a regex from memory and ship it. Use a live tester with real sample data. EazyStudio's Regex Tester shows matches highlighted in real time as you type — use it for every pattern you write.
Test your regex live
Real-time match highlighting, capture groups, and flag toggles — all in browser.
Open Regex Tester