Back to functions
Text2026-11-111 related article

REGEXEXTRACT Function in Excel

Extract matching text or captured groups from a string using a regular expression.

Syntax

REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])
Table of Contents

Arguments

text

Required

The text or cell reference to search.

pattern

Required

The PCRE2 regular expression describing the text to extract.

return_mode

Optional

Use 0 or omit for the first full match, 1 for all full matches, or 2 for captured groups from the first match.

case_sensitivity

Optional

Use 0 or omit for case-sensitive matching; use 1 to ignore case.

What it returns

Returns the first match as text in mode 0, or an array of text values in modes 1 and 2, including when the array contains only one value.

What REGEXEXTRACT does

REGEXEXTRACT pulls matching text out of a longer value. You describe what to find with a regular expression, such as a run of digits or a product-code pattern. Its return mode determines whether you get the first match, all matches, or selected parts captured in parentheses.

The returned values are text. An order number such as 00731 keeps its leading zeros; convert a quantity separately when you need arithmetic. Microsoft's REGEXEXTRACT reference documents the modes and its PCRE2 pattern syntax.

Practical examples

Extract the first run of digits

Put this record in A5:

Order 00731 — 12 units, batch 042
Text

Then enter:

=REGEXEXTRACT(A5,"[0-9]+")
Formula

The result is the text 00731. [0-9] matches an ASCII digit and + allows one or more digits. Omitting the third argument uses mode 0, the first complete match.

Return all the digit groups

Using the same A5, enter this in G5 and leave H5:I5 empty:

=REGEXEXTRACT(A5,"[0-9]+",1)
Formula

The result spills horizontally across G5:I5: 00731 in G5, 12 in H5, and 042 in I5. All three values are text. This one-row, three-column result was verified in Excel for Mac 16.114 (build 16.114.26101123) on November 11, 2026.

Return the order code without its label

Keep the same A5 and use a capturing group:

=REGEXEXTRACT(A5,"Order ([0-9]+)",2)
Formula

The result is 00731. The full pattern matches Order 00731, but mode 2 returns the text captured inside the parentheses. It means captured groups from the first match, not the second match in the cell.

Common mistakes and notes

A digit string is still text

Use VALUE when the extracted item is a quantity you need to calculate with. Keep identifiers as text. For example, converting the extracted order code above would discard its leading zeros.

Your pattern determines which field you get

[0-9]+ finds any run of digits, so it may pick a date or quantity before an ID in a different record layout. Include a reliable label, as in Order ([0-9]+), when the source gives you one. A match doesn't establish that the entire record is valid; REGEXTEST can check a whole-value pattern.

Case and spill room matter

The default match is case-sensitive. Order won't match order unless you set the fourth argument to 1. Multiple results need clear cells in the spill area. In the all-matches example, an occupied cell to the right blocks the horizontal result and produces #SPILL!.

Check the original error before hiding it

=REGEXEXTRACT("No code","[0-9]+") returned #N/A in the same Excel test because the text contains no digits. An error-handling formula can make unresolved rows easy to find, but it can also hide a faulty pattern or unavailable function. Try the extraction alone on a known record first. Microsoft currently lists REGEXEXTRACT for Excel for Microsoft 365 and Excel for Microsoft 365 for Mac.

Related functions

Related articles

Deep dives, troubleshooting guides, and practical examples that use REGEXEXTRACT.

Official documentation