Google Sheets REGEXEXTRACT: Pull Emails, Domains & IDs From Messy Text
Use =REGEXEXTRACT(text, regular_expression) to pull structured codes, email domains, or numbers out of inconsistent notes and URLs without fragile nested LEFT/MID formulas.
1. Basic Syntax & How Capture Groups Work
The syntax for REGEXEXTRACT is:
=REGEXEXTRACT(text, "regular_expression")
text: The cell or text string you want to inspect (for example,A2)."regular_expression": An RE2 pattern wrapped in straight double quotes.- Capture groups
(...): If you include parentheses inside the pattern, Google Sheets returns only the text inside the parentheses rather than the surrounding prefix or delimiter.
2. Worked Examples: Common Extraction Patterns
Here are five copy-ready REGEXEXTRACT formulas tested on messy operational exports:
| Extraction Task | Sample Input (Cell A2) | Formula | Output |
|---|---|---|---|
| Extract email domain | priya@acmeretail.example |
=REGEXEXTRACT(A2, "@(.+)") |
acmeretail.example |
| Extract prefixed Order ID | Payment received for INV-2026-104 (ACH) |
=REGEXEXTRACT(A2, "INV-\d{4}-\d+") |
INV-2026-104 |
| Extract first number (as real number) | Plan: 250 GB Storage |
=VALUE(REGEXEXTRACT(A2, "\d+")) |
250 |
| Extract text inside parentheses | Northstar Logistics (NET-30) |
=REGEXEXTRACT(A2, "\(([^)]+)\)") |
NET-30 |
| Extract domain from full URL | https://knowunlimited.com/excel/query |
=REGEXEXTRACT(A2, "https?://([^/]+)") |
knowunlimited.com |
Numeric tip: REGEXEXTRACT always returns a text string. Wrap it with VALUE(...) whenever you plan to sum or compare extracted numbers.
3. Combining REGEXEXTRACT With ARRAYFORMULA
To extract email domains down an entire column of contacts in A2:A from a single cell at the top of column B:
=ARRAYFORMULA(IF(A2:A="", "", IFERROR(REGEXEXTRACT(A2:A, "@(.+)"), "Invalid Email")))
Learn more about whole-column formulas in our Google Sheets ARRAYFORMULA Guide.
4. Common REGEXEXTRACT Errors & Quick Fixes
#N/A("Function REGEXEXTRACT parameter 2 value ... does not match"): Your pattern did not find a match in that cell (for example, a row missing an@symbol or invoice ID). Wrap the formula inIFERROR(..., "Not Found").#VALUE!(Invalid regular expression or numeric input): Check that special regex characters like(,),[, or.are escaped with a backslash (\() when matching literal characters, and ensure the input cell is text (or coerce withA2&"").- Need interactive error diagnostics? Open our Error Debugger (#N/A) or compare with TEXTSPLIT & SPLIT Guide when your text already has a clean delimiter.
5. Extracting Domains, Order IDs & Numbers Safely
Use parentheses ( ) around the exact substring you want to return, and pair REGEXEXTRACT with IFERROR so rows that don't match a pattern return blank instead of #N/A:
| A | B | |
|---|---|---|
| # | Raw Email / String | Extracted Domain |
| 2 | billing@northstarstudio.com | northstarstudio.com |
| 3 | support@harborlogistics.in | harborlogistics.in |