Spreadsheet Practice

REGEXEXTRACT function in Google Sheets

REGEXEXTRACT pulls out the part of the text that matches a regular expression. Put parentheses around the piece you want and it returns just that group, which makes it a quick way to grab an order number, a domain or a code from messy text.

Works in
Google Sheets only
Returns
Text: the first match, or the captured group or groups. #N/A when nothing matches.

Syntax

=REGEXEXTRACT(text, regular_expression)

ArgumentRequired?What it is
textRequiredThe text to search. It has to be text: wrap numbers in TO_TEXT.
regular_expressionRequiredThe pattern to find. With one capture group in parentheses, only that group comes back; with several, each group fills its own cell.

Examples

Each result is calculated from the sample sheet by our formula engine in Sheets mode, the same one that grades the practice.

CellFormulaResultWhat it shows
B2=REGEXEXTRACT(A2,"@(.+)$")acme.comThe capture group returns just the domain, everything after the @
B3=REGEXEXTRACT(A3,"\d+")4412The first run of digits, 4412, returned as text
B4=REGEXEXTRACT(A4,"(\w+)-(\d+)")INVspills 1 × 2Two capture groups fill two cells: INV in B4 and 2087 in C4

Try it live

This is the sample sheet. Change any value or edit a formula, and the results update.

Practice REGEXEXTRACT

Graded instantly in Sheets mode, then re-checked on changed data.

Pull the order number

In B2, extract the order number (the digits after the #) from the subject line in A2, and turn it into a number with VALUE. Fill down to B7.

Common mistakes

What you seeWhy, and how to fix it
#N/ANothing in the text matched. Check the pattern, or show a fallback: =IFNA(REGEXEXTRACT(A2,"\d+"),"").
The extracted number won't add upREGEXEXTRACT always returns text. Wrap it in VALUE: =VALUE(REGEXEXTRACT(A2,"\d+")).
#VALUE! on a numberLike the other REGEX functions, it needs text. Use TO_TEXT(A2) as the first argument.
Only the first match comes backREGEXEXTRACT stops at the first match. To get more, add capture groups for each piece, or remove what you don't want with REGEXREPLACE.

Tips

  • Start the pattern with (?i) to ignore capitals.
  • Group without returning the group with (?:...): "(?:Mr|Ms)\.? (\w+)" returns just the name after the title.

REGEXEXTRACT in Excel

Recent Microsoft 365 builds have their own REGEXEXTRACT, with extra arguments for returning every match or the capture groups. Other versions use TEXTBEFORE and TEXTAFTER, or MID with FIND.

Questions

How do I extract numbers from text in Google Sheets?

=REGEXEXTRACT(A2,"\d+") returns the first run of digits as text. Wrap it in VALUE to use it as a number, and use "\d+\.?\d*" to include decimals.

How do I extract the domain from an email address?

=REGEXEXTRACT(A2,"@(.+)$") returns everything after the @.

Last reviewed October 2026. Every example result on this page is calculated live by the Spreadsheet Practice formula engine in Sheets mode.