Going Stellar

Home/Google Sheets reference

Google Sheets function · Text

REGEXEXTRACT in Google Sheets: syntax and examples

REGEXEXTRACT returns the first piece of text that matches a regular expression. Use a capture group in parentheses to return only part of the match, such as the domain of an email address.

Try the pattern first in our RE2 regex tester: it uses RE2 syntax, the same as Google Sheets, and runs in your browser.

Syntax

REGEXEXTRACT(text, regular_expression)

Arguments

ArgumentTypeRequiredWhat it does
textstringyesThe text to search.
regular_expressionstringyesA RE2 pattern. With one capture group, only the group is returned. With several, they fill neighbouring cells.

Examples

The examples use this table, starting in A1:

Text
Order #A-1042 shipped
ana.pop@example.com
Price: 129.50 RON
=REGEXEXTRACT(A3, "@(.+)$")

Result: example.com

Domain of an email. The parentheses mark the part to return, so the @ is left out.

Run in a Google Sheet (English US locale) on .

=REGEXEXTRACT(A2, "[A-Z]-\d+")

Result: A-1042

First match of a letter, a dash and digits: the order code.

Run in a Google Sheet (English US locale) on .

=REGEXEXTRACT(A4, "\d+\.\d+")

Result: 129.50

A decimal number inside text. The result is text, not a number.

Run in a Google Sheet (English US locale) on .

=VALUE(REGEXEXTRACT(A4, "\d+"))

Result: 129

VALUE turns the extracted digits into a real number you can add up.

Run in a Google Sheet (English US locale) on .

=REGEXEXTRACT(A3, "(.+)@(.+)")

Result:

ana.popexample.com

Two capture groups spill into two cells: user name, then domain.

Run in a Google Sheet (English US locale) on .

Common errors

  • When nothing matches, REGEXEXTRACT returns #N/A. Wrap it in IFERROR to get an empty cell or a default.
  • A pattern that is not valid, for example an unclosed parenthesis, returns #REF!.
  • The result is text, even for digits. Wrap it in VALUE before adding or comparing numbers.
  • Only the first match is returned. Later matches are ignored.

Compared with Excel

Classic Excel has no REGEXEXTRACT. Excel 365 added one with extra arguments, and its regex flavor differs from the RE2 used in Sheets.

Questions and answers

Is the match case sensitive?

Yes. Add (?i) at the start of the pattern for a case-insensitive match.

Sources

  1. REGEXEXTRACT (Docs Editors Help)

Markdown version · All functions