Quick Answer

REGEXEXTRACT Function

REGEXEXTRACT pulls out the part of a text that matches a regular expression pattern.

✓ Excel✓ Google SheetsExcel Google Sheets only

Syntax

REGEXEXTRACT
(text, regular_expression)

Parameters

ParameterDescriptionRequired
textThe text to search.Required
regular_expressionThe RE2 regular expression pattern. Use parentheses to define capture groups.Required

Basic Example

Extract the domain from an email address

=REGEXEXTRACT('[email protected]', '@(.+)$')
Resultexample.com

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 parsing

Pull first and last names from 'John Smith'

=REGEXEXTRACT(A2, '^(.+)\s+(.+)$')
Result: John Smith (two capture groups)
The first capture group matches the first name, the second matches the last name. In Google Sheets, multiple groups are returned as a horizontal array.

Example 2: Extract an order number

Text parsing

Pull the numeric order ID from 'Order #12345'

=REGEXEXTRACT(A2, 'Order #(\d+)')
Result: 12345
The pattern matches 'Order #' followed by one or more digits and captures the digits.

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.

1
Identify the text to parse
Select the cell or string containing the text.
2
Write a capture pattern
Use parentheses around the part of the pattern you want to extract.
3
Enter the formula
Type =REGEXEXTRACT(text, 'pattern').
4
Handle no match
Wrap with IFERROR if missing matches are expected.

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

Practice 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.

Works in Google SheetsCompatible with ExcelIncludes exercises

File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps

Frequently Asked Questions

Can REGEXEXTRACT return all matches?
No, it returns only the first match. For all matches, you need a helper formula or script.
What if there are multiple capture groups?
Google Sheets returns them as a horizontal array across adjacent cells.
Can I use REGEXEXTRACT in Excel?
No. Excel has no native regex extraction function.
How do I avoid #N/A when there is no match?
Use IFERROR: =IFERROR(REGEXEXTRACT(A2, 'pattern'), 'Not found').