Pattern library / Validation
Practical Email Validation Regex
The full RFC 5322 email grammar is thousands of characters and still wrong at the edges. What you actually need in forms, log filters and analytics segments is a practical pattern: one @, no spaces, a dot-separated domain — roughly 30 characters, valid RE2, and honest about what it does not check.
How the pattern works
[^\s@]+— local part: one or more characters that are neither whitespace nor@.@exactly once, then the domain: anything without spaces/@, a literal dot, then a TLD of at least 2 characters.- It deliberately does not check: quoted local parts (
"weird"@x.com), IP-literal domains (user@[1.2.3.4]), or whether the domain exists. - Deliverability is proven by sending a confirmation email, never by regex. Use this to reject garbage early, not as proof of existence.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
ada@example.com | Match | standard address | Try → |
first.last+tag@sub.domain.co | Match | plus-tag and subdomain | Try → |
no-at-sign.example.com | No match | missing @ | Try → |
spaces here@example.com | No match | no whitespace allowed | Try → |
user@domain | No match | TLD missing (needs dot + 2+) | Try → |
user@.com | No match | empty domain label | Try → |
Where to use it
JavaScript (HTML input)
const re = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
re.test('ada@example.com'); // true
// <input type="email" pattern="[^\s@]+@[^\s@]+\.[^\s@]{2,}">
Python
import re
EMAIL = r'^[^\s@]+@[^\s@]+\.[^\s@]{2,}$'
bool(re.fullmatch(EMAIL, 'ada@example.com'))
BigQuery / GA4 (RE2)
REGEXP_CONTAINS(user_email, r'^[^\s@]+@[^\s@]+\.[^\s@]{2,}$')
Common mistakes
- The famous RFC-complete email regex is unmaintainable and slower — do not paste it from old Stack Overflow answers.
- Single-label TLDs in intranets (user@localhost) fail by design — drop the (\.[^\s@]{2,}) part for internal-only systems.
- Lowercase the domain part before comparing addresses — the local part case rules are messy, domain case is not.
FAQ
Is this email regex RFC 5322 compliant?
No — and that is intentional. It accepts every address people actually use and rejects the garbage. Full RFC compliance requires a parser, not a regex.
Why does user@domain fail?
The pattern requires a literal dot followed by at least two characters (the TLD part). Real public domains always have it; remove \.[^\s@]{2,} if you accept intranet names.
Does this work in GA4 or BigQuery?
Yes — character-class negation, @ and \ . are all RE2-valid. For long email fields prefer BigQuery REGEXP_CONTAINS over GA4 filters.
Related patterns
URL Regex — Match http/https Links (Practical) · Slug Regex — Match lowercase-hyphen URL Slugs · Quoted String Regex — Match "..." and '...'
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.