regex pattern · ready to copy
Regex for matching email addresses
Matches RFC-5322 emails for form validation. Practical, not pedantic.
intermediate
javascript / pcre / python4 use cases
The pattern
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Looser variant (more permissive, fewer false rejects):
[\w.+-]+@[\w-]+\.[\w.-]+
Test cases
| Input | Result |
|---|---|
| alice@voiddo.com | ✓matches |
| user.name+filter@example.co.uk | ✓matches |
| a@b.io | ✓matches |
| plainstring | ✗rejects |
| @no-local.com | ✗rejects |
| missing-domain@ | ✗rejects |
| double@@at.com | ✗rejects |
Edge cases & caveats
Doesn't enforce IDN (international domains) or quoted local-parts. For form validation, use HTML5 `type="email"` first; this regex is for log scraping or list cleanup.
Common use cases
- form input validation
- extract emails from log files
- CSV cleanup before import
- spam list dedup
Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab
Related
uuid · uk postcode · sql injection keywords · ipv4 address · ↗ audit SPF records for the domain