Email Regex Tester
Test and validate email patterns with this specialized regex tester. Includes tested patterns and real-time matching.
Recommended Email Pattern
``regex
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
`
Test Examples
Valid matches:
- user@example.com
john.doe@company.orgtest+label@gmail.com
Invalid (should not match):
user@@example.comuser@.comuser@com
Pattern Explanation
Matches standard email format: local part, @ symbol, domain, and TLD (2+ chars)
Alternative Patterns
1. ^[\w.-]+@[\w.-]+\.\w{2,}$
2. ^.+@.+\..+$
How to Use
1. The pattern above is preloadedβor enter your own
2. Add test strings to validate
3. See real-time match highlights
4. Copy the pattern for your code
Regex Quick Reference
| Symbol | Meaning | Example | ||
|---|---|---|---|---|
| \d | Any digit | \d{3} matches "123" | ||
| \w | Word character | \w+ matches "hello" | ||
| + | One or more | a+ matches "aaa" | ||
| * | Zero or more | a* matches "" or "aaa" | ||
| ? | Optional | colou?r matches "color" | ||
| ^ | Start of string | ^Hello | ||
| $ | End of string | world$ | ||
| [abc] | Character class | [aeiou] matches vowels | ||
| (a | b) | Alternation | (cat | dog) matches either |
The Pattern
`regex
^[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$
`
Flags: gm β m makes ^ and $ match at each line break, so the pattern can be tested against a list.
Broken Down
| Part | What it does |
|---|---|
^[\w.%+-]+ | local part β letters, digits, underscore, dot, percent, plus, hyphen |
@ | the literal separator |
[A-Za-z0-9.-]+ | domain labels and their separators |
\.[A-Za-z]{2,}$ | a TLD of at least two letters, anchored to the end |
Tested Against Real Input
| Input | Result |
|---|---|
ada@example.com | β matches |
first.last+tag@sub.domain.co.uk | β matches |
not-an-email@ | β no match |
@missing-local.com | β no match |
The Important Caveat
No regex fully validates an email address β RFC 5322 permits quoted strings, comments and nested parentheses that no readable pattern captures. Use a permissive pattern to catch typos, then send a confirmation email. That is the only real validation.
Using It
`javascript
const pattern = /^[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/gm;
// Test a single value β reset lastIndex first if the pattern is global
pattern.lastIndex = 0;
const isValid = pattern.test(value);
// Or find every match in a block of text
const matches = [...text.matchAll(pattern)];
`
A global regex carries lastIndex between calls, so reusing one across test() calls
returns alternating results. Either drop the g flag for validation or reset it each time.
Anchors, Greediness and Backtracking
Three behaviours account for most regex surprises, and this pattern shows all three.
Anchors. ^ and $ pin the match to the start and end of the input. Without them,
\d{3} matches the 123 inside abc123def. With m in the flags β as here β they
pin to each *line* instead, which is what lets one pattern be tested against a list.
Greediness. .* takes as much as it can and gives back only when forced; .*? takes
as little as possible. On , the pattern <.*> matches the whole string and
<.*?> matches just .
Testing It Properly
`javascript
const pattern = /^[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/gm;