REGEXEXTRACT Function
REGEXEXTRACT pulls out the part of a text that matches a regular expression pattern.
Syntax
Parameters
| Parameter | Description | Required |
|---|---|---|
| text | The text to search. | Required |
| regular_expression | The RE2 regular expression pattern. Use parentheses to define capture groups. | Required |
Basic Example
Extract the domain from an email address
=REGEXEXTRACT('[email protected]', '@(.+)$')The pattern captures everything after the @ symbol and before the end of the string.
Advanced Examples
Example 1: Extract first and last name from a full name
Name parsingPull first and last names from 'John Smith'
=REGEXEXTRACT(A2, '^(.+)\s+(.+)$')Example 2: Extract an order number
Text parsingPull the numeric order ID from 'Order #12345'
=REGEXEXTRACT(A2, 'Order #(\d+)')How REGEXEXTRACT Works
REGEXEXTRACT searches the text for the first match of the regular expression. If the pattern contains capture groups, the captured text is returned. Without capture groups, the entire match is returned. If there is no match, the function returns #N/A.
Important Notes & Limitations
REGEXEXTRACT is Google Sheets only. Excel has no built-in regex extraction function.
It uses RE2 syntax, which lacks lookahead/lookbehind and some advanced features.
Only the first match is returned. For multiple matches, you need a more complex approach or REGEXREPLACE.
Multiple capture groups return a horizontal array, which may spill across columns.
Common Errors & Fixes
#N/A errorNo match was found for the pattern.Fix: Check the pattern or wrap with IFERROR to return a default value.
#VALUE! errorThe regular expression is invalid.Fix: Validate the regex syntax and ensure it is RE2-compatible.
Wrong extractionCapture groups are not defined correctly.Fix: Place parentheses around only the text you want to extract.
Download Practice File
REGEXEXTRACT
regexextractPractice REGEXEXTRACT with Real Data
Download a sample CSV file with pre-populated data and practice exercises for the REGEXEXTRACT function. Works in both Excel and Google Sheets.
File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps