REGEXEXTRACT in Google Sheets pulls the part of a cell that matches a pattern, which makes it the quickest way to clean messy exports, CRM dumps and pasted text. This guide gives you tested patterns for emails, phone numbers, order IDs, dates and URLs, shows their results on sample rows, and explains the RE2 rules and errors that trip people up.
Quick answer: =REGEXEXTRACT(A2, "pattern") returns the first part of A2 that matches the regular expression. Wrap it in IFERROR(…, "") so rows without a match stay blank, and put the part you want in parentheses to return only that part.
- Keep the messy text in column A, starting in A2.
- In B2, enter a pattern formula from this guide, for example the email pattern.
- Fill the formula down, or use ARRAYFORMULA for the whole column.
- Use a capture group instead of lookahead or lookbehind, which Google Sheets (RE2) does not support.
- Wrap numeric cells in TO_TEXT() first, because REGEXEXTRACT only accepts text.
In this guide
- Why REGEXEXTRACT in Google Sheets
- Syntax and RE2 engine facts
- Worked example: three messy rows
- Copy‑ready patterns for common tasks
- Advanced patterns you’ll actually use
- Regex pitfalls in Google Sheets (RE2 realities)
- Build a cleaning pipeline (ARRAYFORMULA + REGEX)
- REGEXEXTRACT vs REGEXREPLACE vs REGEXMATCH (comparison)
- Practical applications (real‑world)
- Data hygiene tips
- Alternatives and complements
- Implementation guide: clean a messy contact column in 15 minutes
- Common REGEXEXTRACT errors and fixes
- Frequently Asked Questions
- Next steps
- Official docs and trusted sources
Why REGEXEXTRACT in Google Sheets
REGEXEXTRACT pulls the first substring that matches a regular expression. Because Google Sheets uses the RE2 engine, your patterns are fast, safe, and predictable—great for cleaning marketing lists, logs, and lead captures at scale.
- Extract structured values from unstructured blobs: emails, phones, IDs, dates, URLs.
- Build repeatable pipelines: combine with
ARRAYFORMULA,QUERY, andIFERROR. - Scale to thousands of rows with consistent logic and fewer manual edits.
Syntax and RE2 engine facts
The core formula:
=REGEXEXTRACT(text, regular_expression)- Engine: RE2 (Google). That means no lookahead or lookbehind and no backreferences inside a pattern; lazy quantifiers like
.*?are supported. - First match only: REGEXEXTRACT returns the first match. Sheets has no native "all matches" extractor, so pair it with
REGEXREPLACEorSPLIT, or split the work into steps. - Capturing groups: with no parentheses, REGEXEXTRACT returns the whole match. With one or more capture groups
()it returns only the groups, one per column. Use(?:...)for grouping that should not be captured.
Worked example: three messy rows
Here is what the patterns in the next section return on three rows of pasted text. Column B uses the phone pattern (pattern 3, step 1), C strips B to digits (step 2), D uses the email pattern (1) and E the order ID pattern (4):
| A: raw text | B: phone | C: digits | D: email | E: order ID | |
|---|---|---|---|---|---|
| 2 | Call Maria at (415) 555-0132 or email maria.lopez@example.com re ORD-2026-000123 | (415) 555-0132 | 4155550132 | maria.lopez@example.com | ORD-2026-000123 |
| 3 | Order ORD-2026-000456 shipped, contact: jkim@shop.example.org, +1 212.555.0199 | +1 212.555.0199 | 12125550199 | jkim@shop.example.org | ORD-2026-000456 |
| 4 | No contact details, see https://example.com/help?id=7 | (blank) | (blank) | (blank) | (blank) |
Row 4 has no match for any of the four patterns, so IFERROR leaves the cells blank instead of showing #N/A. The URL pattern (2) would return https://example.com/help?id=7 for that row. Note that the phone pattern skips the digits inside the order ID in row 3, because they do not form a 3-3-4 group.
Copy‑ready patterns for common tasks
1) Extract the first email address
=IFERROR(REGEXEXTRACT(A2, "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"), "")2) Extract the first URL (http/https)
=IFERROR(REGEXEXTRACT(A2, "https?://[^\s)]+"), "")3) Extract a US‑style phone, then normalize digits
Step 1: capture a plausible phone (here in B2):=IFERROR(REGEXEXTRACT(A2, "(?:\+1[ .-]*)?(?:\(\d{3}\)|\d{3})[ .-]?\d{3}[ .-]?\d{4}"), "")=IF(LEN(B2), REGEXREPLACE(B2, "\D", ""), "")TEXT or REGEXREPLACE.
4) Extract an order ID pattern (e.g., ORD-2026-000123)
=IFERROR(REGEXEXTRACT(A2, "ORD-\d{4}-\d{6}"), "")5) Extract ISO date (YYYY‑MM‑DD)
=IFERROR(REGEXEXTRACT(A2, "\b\d{4}-\d{2}-\d{2}\b"), "")DATEVALUE if needed: =IFERROR(DATEVALUE(C2), "").
6) Extract UTM parameters from a URL
Campaign, medium, and source (one formula per cell):=IFERROR(REGEXEXTRACT(A2, "[?&]utm_campaign=([^&]+)"), "")
=IFERROR(REGEXEXTRACT(A2, "[?&]utm_medium=([^&]+)"), "")
=IFERROR(REGEXEXTRACT(A2, "[?&]utm_source=([^&]+)"), "")= is returned. Sheets has ENCODEURL but no built-in function to decode a URL. For simple cases wrap the result in SUBSTITUTE, e.g. =SUBSTITUTE(SUBSTITUTE(B2, "%20", " "), "+", " "), or add a small Apps Script custom function that calls decodeURIComponent.
Advanced patterns you’ll actually use
Bounded matches: avoid over‑capture
=IFERROR(REGEXEXTRACT(A2, "\b[A-Z]{2}\d{6}\b"), "")\b adds word boundaries—great for IDs like AB123456 surrounded by punctuation.
Stop at a delimiter with a capture group (RE2 has no lookahead)
Capture everything before - (space, dash, space):
=IFERROR(REGEXEXTRACT(A2, "^(.+?) - "), "").+?(?= - ) works in other regex engines but returns an error in Sheets. Put the part you want inside () and leave the delimiter outside it: REGEXEXTRACT returns only the captured group.
Capture the Nth match by pre‑trimming
Get the second email by removing the first one, then extracting again:=LET(
pattern, "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}",
first, IFERROR(REGEXEXTRACT(A2, pattern), ""),
rest, IF(first = "", A2, SUBSTITUTE(A2, first, "", 1)),
IFERROR(REGEXEXTRACT(rest, pattern), "")
)Regex pitfalls in Google Sheets (RE2 realities)
- No lookahead or lookbehind: wrap the part you want in a capture group, or use
REGEXREPLACE. - Text only: REGEXEXTRACT returns an error on numeric cells; wrap the input in
TO_TEXT()first. - Greedy vs lazy: Prefer lazy
.*?when you want the shortest run to a delimiter. - Performance: Constrain with anchors, boundaries, and literal prefixes to avoid scanning huge strings.
Build a cleaning pipeline (ARRAYFORMULA + REGEX)
Scale your cleaning across a whole column withARRAYFORMULA, fail‑safes, and normalization: Put this in B1 to fill column B with the emails found in column A:
=ARRAYFORMULA(IF(ROW(A:A)=1, "Email", IF(A:A="", , IFERROR(REGEXEXTRACT(A:A, "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}"), ""))))REGEXEXTRACT vs REGEXREPLACE vs REGEXMATCH (comparison)
- REGEXEXTRACT: return first matching substring.
- REGEXREPLACE: transform by replacing parts using patterns and
$1-style group references. - REGEXMATCH: TRUE/FALSE filter to test if a pattern exists.
=FILTER(A2:A, REGEXMATCH(A2:A, "ORD-\d{4}-\d{6}"))=IFERROR(REGEXEXTRACT(A2, "ORD-\d{4}-\d{6}"), "")Practical applications (real‑world)
- Marketing lists: Pull valid emails from mixed notes, clean phones for dialers.
- Analytics QA: Extract UTM params, domain names, campaign names from URLs.
- Support logs: Extract ticket IDs from noisy clipboard pastes.
- Finance ops: Extract invoice IDs and ISO dates for reconciliation.
Data hygiene tips
- Schema first: Decide final columns (Email, Phone, URL, ID) and normalize to those.
- Guardrails: Wrap with
IFERROR(..., "")to avoid #N/A cascades. - Pre‑filter: Use
QUERYorREGEXMATCHto keep rows worth processing. - Document patterns: Add a hidden “Patterns” tab with examples and unit‑test cases.
Alternatives and complements
- SPLIT: Great when delimiters are predictable; regex when they aren’t.
- Apps Script: Write custom cleaners if you need multi‑match extraction per cell.
- IMPORTXML/IMPORTHTML: Pull structured tables; regex for the final nudge on tricky fields.
Implementation guide: clean a messy contact column in 15 minutes
- Duplicate your raw sheet and create a Working tab.
- Add headers: Email, Phone, URL, Notes.
- Extract emails from the raw text column with the email pattern.
- Extract phones, strip non‑digits, and re‑format to your standard.
- Extract URLs for source attribution and QA.
- Add a Valid row flag: with Email in column B and Phone in column C, use
=OR(LEN(B2)>0, LEN(C2)>0)and fill it down. - Filter to Valid=TRUE and export to your CRM.
Common REGEXEXTRACT errors and fixes
- #N/A saying the pattern does not match the text: there is no match in that cell. This is normal for rows without the value; wrap the formula in
IFERROR(…, ""). If every row fails, test the pattern on one cell you know contains a match. - #REF! saying the value is not a valid regular expression: the pattern uses syntax RE2 does not support, most often a lookahead
(?=…), a lookbehind(?<=…)or a backreference such as\1. Rewrite it with a capture group. - #VALUE! saying the function expects text values: the input cell holds a number or date. Wrap it:
REGEXEXTRACT(TO_TEXT(A2), …). - The result spreads over several columns: each pair of parentheses is a capture group and gets its own column. Turn groups you only use for alternatives into non-capturing groups with
(?:…). - #REF! “Array result was not expanded because it would overwrite data”: a multi-group pattern or an ARRAYFORMULA needs empty cells to the right or below. Clear them.
In general, keep patterns simple and bounded, pair REGEXEXTRACT with REGEXREPLACE for normalization (digits only, lowercase domains), and test every pattern on a few sample rows before you fill a whole column.
Frequently Asked Questions
Does Google Sheets support lookahead or lookbehind in regex?
No. Google Sheets uses the RE2 engine, which supports neither lookahead nor lookbehind, and a pattern that uses them returns an error. Put the part you want inside a capture group ( ) and leave the surrounding text outside it, or use anchors such as ^ and $.
How do I get the second or third match?
REGEXEXTRACT only returns the first match. Remove the first match with SUBSTITUTE and run REGEXEXTRACT again, as in the LET example above. For many matches per cell, an Apps Script custom function that uses JavaScript’s matchAll is simpler.
Can REGEXEXTRACT return several values at once?
Yes, with several capture groups. Each group goes into its own column, so =REGEXEXTRACT(A2, "(\d{4})-(\d{2})-(\d{2})") on 2026-03-15 returns 2026, 03 and 15 in three adjacent cells. Keep the cells to the right empty.
How do I make REGEXEXTRACT case-insensitive?
Start the pattern with the RE2 flag (?i). For example, =REGEXEXTRACT(A2, "(?i)ord-\d{4}-\d{6}") matches both ORD-2026-000123 and ord-2026-000123. Without the flag, letters must match the case exactly.
Should I use REGEXEXTRACT or SPLIT?
Use SPLIT when the data is cleanly delimited, such as values separated by commas; it is simpler to read. Use REGEXEXTRACT when the delimiter varies or the value sits somewhere inside free text, like an email in a note.
Next steps
Paste the three sample rows into a blank sheet, add the formulas and check that you get the same results; then point them at your own data. If the messy data comes from several team files, combine them first with the IMPORTRANGE master sheet guide. Once the columns are clean, summarize them with the QUERY function.
Official docs and trusted sources
- Google — REGEXEXTRACT: support.google.com/docs/answer/3098244
- Google — RE2 syntax guide: github.com/google/re2/wiki/Syntax
- Google — REGEXREPLACE: support.google.com/docs/answer/3098245
- Google — REGEXMATCH: support.google.com/docs/answer/3098292

