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)
| Argument | Required? | What it is |
|---|---|---|
text | Required | The text to search. It has to be text: wrap numbers in TO_TEXT. |
regular_expression | Required | The 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.
| Cell | Formula | Result | What it shows |
|---|---|---|---|
| B2 | =REGEXEXTRACT(A2,"@(.+)$") | acme.com | The capture group returns just the domain, everything after the @ |
| B3 | =REGEXEXTRACT(A3,"\d+") | 4412 | The first run of digits, 4412, returned as text |
| B4 | =REGEXEXTRACT(A4,"(\w+)-(\d+)") | INVspills 1 × 2 | Two 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
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 see | Why, and how to fix it |
|---|---|
| #N/A | Nothing in the text matched. Check the pattern, or show a fallback: =IFNA(REGEXEXTRACT(A2,"\d+"),""). |
| The extracted number won't add up | REGEXEXTRACT always returns text. Wrap it in VALUE: =VALUE(REGEXEXTRACT(A2,"\d+")). |
| #VALUE! on a number | Like the other REGEX functions, it needs text. Use TO_TEXT(A2) as the first argument. |
| Only the first match comes back | REGEXEXTRACT 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.