# REGEXEXTRACT function in Excel

> REGEXEXTRACT pulls out the part of a text that matches a regular expression: an order number, an email domain, the digits in a messy code.

Source: https://spreadsheetpractice.com/functions/regexextract · Updated October 28, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on October 30, 2026

## Quick answer

- **What it does:** REGEXEXTRACT pulls out the part of a text that matches a regular expression: an order number, an email domain, the digits in a messy code.
- **Syntax:** `=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])`
- **Most common use:** `=REGEXEXTRACT(A2,"\d+")` returns 48213 (The first run of digits, as text)
- **Available in:** Microsoft 365 only
- **Category:** [Text functions](https://spreadsheetpractice.com/functions/category/text)
- **Returns:** Text, or an array of text for return_mode 1 and 2; #N/A if nothing matches.
- **Google Sheets:** Google Sheets has REGEXEXTRACT with two arguments: it returns the first match, or the capture groups when the pattern has them.

## What it does

REGEXEXTRACT pulls out the part of a text that matches a regular expression: an order number, an email domain, the digits in a messy code. By default it returns the first match; return_mode 1 returns every match and 2 returns the capture groups. It returns #N/A when nothing matches.

## Syntax

`=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])`

| Argument | Required? | What it is |
|---|---|---|
| `text` | Required | The text to search. |
| `pattern` | Required | The regular expression, in quotes. |
| `return_mode` | Optional | Optional: 0 (default) the first match, 1 every match as an array, 2 the capture groups of the first match. |
| `case_sensitivity` | Optional | Optional: 0 (default) for case-sensitive, 1 to ignore case. |

## Examples

Each result was calculated by running the formula on the sample sheet.

| Cell | Formula | Result | What it shows |
|---|---|---|---|
| B2 | `=REGEXEXTRACT(A2,"\d+")` | 48213 | The first run of digits, as text |
| B3 | `=REGEXEXTRACT(A3,"\d{3}-\d{4}",1)` | 555-0142 (spills 1 × 2) | Every phone number, spilled across the row |
| B4 | `=REGEXEXTRACT(A4,"@(.+)",2)` | contoso.com | Only the capture group: the domain |

### The sample sheet

Every formula above runs on this data:

|  | A | B | C |
|---|---|---|---|
| 1 | Note | Result |  |
| 2 | Order 48213 shipped | 48213 |  |
| 3 | Call 555-0142 or 555-0199 | 555-0142 | 555-0199 |
| 4 | ana.lopez@contoso.com | contoso.com |  |

## Common mistakes

| What you see | Why, and how to fix it |
|---|---|
| #N/A | Nothing matched. Check the case (matching is case-sensitive by default), or wrap it: =IFNA(REGEXEXTRACT(A2,"\d+"),""). |
| The number won't add up | REGEXEXTRACT returns text. Wrap it in VALUE, or use --REGEXEXTRACT(…), to get a number. |
| #SPILL! | return_mode 1 and 2 return several values that need empty cells to the right. |

## Tips

- Capture groups in parentheses pick out just part of the match: =REGEXEXTRACT(A2,"ID: (\d+)",2) returns only the digits.

## Related functions

- [REGEXREPLACE](https://spreadsheetpractice.com/functions/regexreplace): REGEXREPLACE replaces the parts of a text that match a regular expression.
- [REGEXTEST](https://spreadsheetpractice.com/functions/regextest): REGEXTEST checks whether text contains a match for a regular expression and returns TRUE or FALSE.
- [TEXTAFTER](https://spreadsheetpractice.com/functions/textafter): TEXTAFTER returns everything after a delimiter, such as the domain after the @ or the last part of a file path.

## Questions

### How do I extract numbers from text in Excel?

=REGEXEXTRACT(A2,"\d+") returns the first run of digits as text; =--REGEXEXTRACT(A2,"\d+") makes it a number.

### How do I extract every match?

Set return_mode to 1: =REGEXEXTRACT(A2,"\d+",1) spills every run of digits across a row.

## Practice

A graded REGEXEXTRACT exercise ("Pull the invoice number") is on [the REGEXEXTRACT page](https://spreadsheetpractice.com/functions/regexextract). It is checked instantly, then re-checked on changed data.

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
