REGEXEXTRACT Function in Google Sheets
Extracts the first substring of text matching a regular expression. The Swiss army knife of text parsing in Google Sheets.
Syntax
REGEXEXTRACT(text, regular_expression)Returns: The first match of the regex in text, or #N/A if no match.
Excel equivalent: No direct equivalent. Excel users typically use Power Query or VBA for regex.
Parameters
| Name | Required | Description |
|---|---|---|
| text | Required | The string to search in. |
| regular_expression | Required | A regex pattern using Google's RE2 syntax (similar to but more restricted than PCRE). |
Examples
Pull the domain from an email
=REGEXEXTRACT(A2, "@(.+)$")Captures everything after the @ symbol. The parentheses create a capture group — REGEXEXTRACT returns the captured part.
Get the first number in a string
=REGEXEXTRACT(A2, "\d+")Matches the first sequence of digits. Useful for pulling order numbers, prices, etc., from messy text.
Parse a date format
=REGEXEXTRACT(A2, "(\d{4})-(\d{2})-(\d{2})")With multiple capture groups, REGEXEXTRACT returns just the first — wrap with ARRAYFORMULA + multiple calls to get all of them.
When to use an alternative
- SPLIT — Your text has a fixed delimiter.
- FIND + LEFT/MID/RIGHT — You want explicit positional logic without regex.
- REGEXMATCH — You only want to know IF the pattern matches, not the extracted value.
Common errors and how to fix them
#N/A
Cause: Pattern doesn't match any part of text.
Fix: Wrap with IFERROR for a fallback. Test the regex against sample data at regex101.com (set to RE2 syntax).
Returns whole match instead of captured group
Cause: Forgot the parentheses around the part you want extracted.
Fix: Wrap the target part in parentheses: "@(.+)$" not "@.+$".
RE2 syntax limitations
Cause: Used a feature not supported by Google's RE2 engine (e.g., lookbehind, conditional patterns).
Fix: Rewrite using only RE2-supported features. Check Google's docs for the supported subset.
Related functions
Frequently Asked Questions
What regex flavor does REGEXEXTRACT use?
Google Sheets uses the RE2 engine — same as Go and most Google products. It's similar to PCRE but doesn't support lookbehind, backreferences in patterns, or some other advanced features. Test patterns at regex101.com set to RE2 flavor.
How do I extract multiple matches?
REGEXEXTRACT returns only the first match. For all matches, either: (1) use REGEXEXTRACT with a more specific pattern repeatedly with different starting offsets, (2) use Apps Script with the matchAll method, or (3) restructure your source data so each match lives on its own row.