Regex Guide · Prompt: “Match valid email addresses and capture the local username and domain in separate groups”
Regular Expression for Email Validation & Extraction
Verified by LiveFormulaLab Engineering Team • Updated November 2026
Validate and extract email addresses with a clean regular expression. Test against valid and invalid emails live with capture groups.
Verified Regex Syntax
([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})How This Formula Works (Step-by-Step)
A practical email regex balances accuracy with readability across JavaScript, Python, SQL, and Google Sheets.
Step 1: ([a-zA-Z0-9._%+-]+) captures the local mailbox name before the @ sign.
Step 2: @([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}) captures the hostname and requires at least a 2-letter top-level domain.
Formula Syntax & Arguments Breakdown
Matches the mailbox local-part, literal "@" separator, and domain hostname with a 2+ letter top-level extension, separating username and domain into dedicated capture groups for form validation or CRM enrichment.
| Argument / Clause | Requirement | Data Type | Role & Behavior |
|---|---|---|---|
([a-zA-Z0-9._%+-]+) | Required | Capture Group 1 | Matches one or more valid local mailbox characters including dots, underscores, hyphens, and plus tags. |
@ | Required | Literal Delimiter | Requires the single "@" separator between local username and domain hostname. |
([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}) | Required | Capture Group 2 | Captures the domain name and enforces at least one dot plus a 2+ letter top-level domain. |
^ ... $ anchors (optional) | Optional | Line Boundaries | Wrap the pattern in ^ and $ when validating standalone input boxes; omit anchors when extracting emails inside longer paragraphs. |
3 Real-World Use Cases
- Validating signup form email inputs in frontend and backend JavaScript.
- Extracting email addresses from messy customer support transcripts.
- Auditing CRM CSV uploads in Google Sheets with REGEXMATCH.
Cross-Platform Equivalents
- Excel
=REGEXEXTRACT(A2, "([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})")- SQL
SELECT email FROM users WHERE email ~* '^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}#39;;- Python Pandas
df[df['email'].str.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}#39;)]
Common Mistakes & Pro Tips
Pitfalls & How to Fix Them
Mistake: Validating form inputs without ^ and $ anchors accepts strings like "bad email: a@b.com!!!" because a substring matched.
Fix: Add ^ at the start and $ at the end when validating standalone email fields.
Mistake: Forgetting to escape the dot (.) before the TLD allows any character (like a@bXcom) to match.
Fix: Always escape literal dots as \. inside regular expressions.
Mistake: Restricting the TLD to {2,4} rejects modern valid extensions like .cloud, .digital, or .company.
Fix: Use {2,} without an upper cap so newer multi-letter domains pass cleanly.
Engineering Pro Tips
- Always trim whitespace before testing user input against an anchored email regex.
- Use HTML5 validation or a syntax regex for instant feedback, backed by a verification email for true deliverability.
- In Google Sheets, =REGEXMATCH(A2, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}quot;) flags invalid rows in bulk.
- Normalize captured domains to lowercase in SQL or Python before counting unique company accounts.
Frequently Asked Questions
- Should I anchor the regex with ^ and $ when validating form fields?
- Yes, wrap the pattern as ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ to require the whole string to be one email.
- Does this allow plus-addressed emails like name+tag@company.com?
- Yes, the + character is explicitly included in the first character class.
- How do I run this inside Google Sheets?
- Use =REGEXMATCH(A2, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}quot;).
Related Formulas & Guides
- Extract Numbers and Decimals From Text Using Regex — Extract integers, decimals, and prices from mixed text strings using Regex. Test live with interactive match highlighting.
- Validate YYYY-MM-DD ISO Dates with Regular Expressions — Validate and extract strict YYYY-MM-DD calendar dates with Regex, rejecting invalid months (>12) and days (>31). Test live.
- Strong Password Validation Regex Using Lookaheads — Enforce strong password complexity with positive lookaheads in Regex (8+ characters, uppercase, lowercase, digit, symbol). Test live.
- Extract Domain and Path From URLs Using Regex — Parse scheme, domain hostname, and path from HTTP/HTTPS URLs using a clean Regex pattern with capture groups. Test interactively live.