[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,} This pattern finds email addresses embedded in larger text, without anchors, using the global flag to collect every occurrence. It is the extraction counterpart to the anchored email validation pattern. Extraction patterns pull substrings out of larger text rather than judging the whole input. They usually omit anchors and use the global flag to find every occurrence, often with capturing groups to isolate the part you want. Typical uses are scraping emails, URLs, tags or mentions from prose, logs and documents, where the surrounding text is irrelevant noise. It uses the g flag(s). Apply it across text to collect every occurrence. Without anchors it can match partial or trailing punctuation oddly; trim surrounding characters from results. It is more permissive than the validation pattern (allows % and + in the local part), suited to scanning rather than strict checking. Extraction may catch obfuscated addresses (user [at] domain) only if they use a real @; obfuscation defeats it. As with any regular expression, confirm its behavior in your target engine, test boundary and adversarial inputs, and watch for catastrophic backtracking before relying on it in production.
Token-by-token explanation
[A-Za-z0-9._%+-]+ — local part allowing common email characters@ — the literal at-sign[A-Za-z0-9.-]+ — domain labels and dots\.[A-Za-z]{2,} — a dot then an alphabetic TLD of two or more lettersg flag — find all matches, not just the first
What it matches
contact ada@example.com nowa@b.co and c@d.orguser+tag@sub.domain.io What it does not match
no email here@missing-local.comuser@domain When to use it
Reach for an extraction pattern when you need to pull structured tokens out of unstructured text: scraping contact details from a page, collecting links from a log, or harvesting tags from social content. Use capturing groups to isolate the part you want and the global flag to gather every occurrence. Clean the results afterward — extraction often grabs trailing punctuation or partial matches, so trim and deduplicate before storing or displaying the collected values.
Caveats
- Without anchors it can match partial or trailing punctuation oddly; trim surrounding characters from results.
- It is more permissive than the validation pattern (allows % and + in the local part), suited to scanning rather than strict checking.
- Extraction may catch obfuscated addresses (user [at] domain) only if they use a real @; obfuscation defeats it.
Code examples
const re = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
const text = "see contact ada@example.com now and more";
const found = [...text.matchAll(re)].map(m => m[1] ?? m[0]);
// found holds every extracted occurrence import re
rx = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
text = "see contact ada@example.com now and more"
found = rx.findall(text) # every occurrence (groups if present) import java.util.regex.*;
Pattern p = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}");
Matcher m = p.matcher("contact ada@example.com now");
boolean ok = m.find(); // scan for occurrences <?php
$subject = "contact ada@example.com now";
if (preg_match_all('/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/', $subject, $m)) {
// $m[0] is the full match; $m holds every occurrence
} How to test it
Before trusting any pattern, test it against three kinds of input: valid examples that must match, invalid examples that must be rejected, and edge cases at the boundaries (empty strings, maximum lengths, unusual separators and Unicode). Paste the expression into a live regex tester with your actual sample data and confirm the highlighted matches are exactly what you intend. Watch for catastrophic backtracking by trying long non-matching inputs, and remember that engine differences (JavaScript, Python, Java, PCRE, Go/RE2) mean a pattern that works in one may fail or behave differently in another — especially lookarounds, which Go's RE2 does not support at all.
Frequently asked questions
Why no ^ and $ anchors here?
Anchors would require the entire string to be one email. For extraction from prose we omit them and use the g flag to find every embedded address.
How do I avoid matching trailing punctuation?
Post-process matches to strip trailing dots or commas, or refine the TLD class; the simple pattern may include a sentence-ending period in some cases.
Why do extraction patterns use the global flag?
Without g (or findall/preg_match_all), only the first occurrence is returned. The global flag iterates every match in the text, which is what you want when pulling all emails, URLs or tags from a document.
How do I capture just the part I want?
Wrap the target in a capturing group ( ... ) and read group 1 from each match. Use non-capturing groups (?: ... ) for structure you do not need, keeping the group numbering clean and predictable.
Try the Regex Tester
Live regex matching with groups, flags and explanations.