Text

REGEXEXTRACT Function in Excel

Extracts text that matches a regular expression pattern, optionally from a capture group.

Syntax

  • =REGEXEXTRACT(text, pattern, [return_num], [case_insensitive])

Arguments

  • text (required): Text to search
  • pattern (required): Regular expression with optional capture groups ()
  • return_num (optional): Which capture group to return (default 1)
  • case_insensitive (optional): TRUE to ignore case (default FALSE)

Examples

  • =REGEXEXTRACT("Order INV-123456", "(\\d{6})") - Extract 6-digit ID - Result: 123456
  • =REGEXEXTRACT(A2, "@(.+)$", 1) - Extract domain from email - Result: mail.com
  • =REGEXEXTRACT(A2, "(\\d+)", 1) - First run of digits - Result: Numeric substring

Excel REGEXEXTRACT function documentation

  • REGEXEXTRACT returns text that matches a capture group in a regular expression — the extract counterpart to [REGEXTEST](/functions/regextest/).
  • Syntax: =REGEXEXTRACT(text, pattern, [return_num], [case_insensitive]). return_num selects which capture group to return.
  • Use to pull domains from emails, invoice numbers from notes, or JSON-like fragments when Power Query is overkill.
  • Works best on consistent text; pair with [TRIM](/functions/trim/) and [CLEAN](/functions/clean/) after extraction.

REGEXEXTRACT syntax and capture groups

  • text (required): source string.
  • pattern (required): regex with parentheses () defining capture groups — group 1 is return_num=1 by default.
  • return_num (optional): which capture group to return when multiple () groups exist.
  • case_insensitive (optional): TRUE for case-insensitive matching.
  • Example: =REGEXEXTRACT(A2, "@(.+)$", 1) extracts domain from email when pattern captures after @.

Worked REGEXEXTRACT examples

  • Extract digits: =REGEXEXTRACT(A2, "(\\d+)") returns first run of digits from mixed text.
  • Invoice ID: =REGEXEXTRACT(A2, "INV-(\\d{6})", 1) when notes contain "INV-123456".
  • URL domain: =REGEXEXTRACT(A2, "https?://([^/]+)", 1) for simple URL lists.
  • Multiple groups: use return_num=2 to return the second parenthesized group in the pattern.

REGEXEXTRACT vs TEXTBEFORE / TEXTAFTER

  • Use [TEXTBEFORE](/functions/textbefore/) / [TEXTAFTER](/functions/textafter/) when a single delimiter splits reliably.
  • Use REGEXEXTRACT when the pattern is variable (optional segments, alternation, digit counts).
  • Use [REGEXREPLACE](/functions/regexreplace/) when you need to rewrite matched text, not only extract.
  • Legacy Excel: combine MID, FIND, and LEN — or upgrade path documented in [XLOOKUP era guides](/guides/).

People also ask

  • What does REGEXEXTRACT return if no match? — #CALC! or empty depending on build; wrap with IFERROR for labels.
  • How many capture groups? — return_num picks among () groups in your pattern; ungrouped matches may differ by version.
  • REGEXEXTRACT on spilled arrays? — Apply row-by-row or use BYROW with LAMBDA in M365.

Common errors

  • #CALC! or error when no match
  • #NAME? without regex support
  • Invalid capture group index

Use cases

  • Parse invoice IDs
  • Extract domains
  • Pull numeric codes from notes

Frequently asked questions

  • What is REGEXEXTRACT used for? It returns substrings that match a regex pattern — especially useful with capture groups to pull IDs, domains, or numeric blocks from messy text.
  • What is return_num in REGEXEXTRACT? It selects which parenthesized capture group to return. return_num=1 is the first () group in your pattern.
  • REGEXEXTRACT vs MID and FIND? Use MID/FIND for simple delimiters. Use REGEXEXTRACT when the format varies or needs pattern rules like digit counts and optional segments.

Editorial review

  • Reviewed by Excel.Directory Editorial Team. Updated May 2026.

When to use REGEXEXTRACT

  • Parse invoice IDs — common Text scenario for REGEXEXTRACT.
  • Extract domains — common Text scenario for REGEXEXTRACT.
  • Pull numeric codes from notes — common Text scenario for REGEXEXTRACT.

REGEXEXTRACT in the Text category

  • Browse all Text functions at /categories/text/ for related formulas.
  • REGEXEXTRACT syntax: =REGEXEXTRACT(text, pattern, [return_num], [case_insensitive])
  • text (required): Text to search
  • pattern (required): Regular expression with optional capture groups ()
  • return_num (optional): Which capture group to return (default 1)
  • case_insensitive (optional): TRUE to ignore case (default FALSE)
  • Confirm REGEXEXTRACT arguments match the syntax shown above before filling down.
  • Lock table and range references with $ when copying formulas across rows or sheets.

Formula checklist before you copy down

  • Confirm REGEXEXTRACT arguments match the syntax shown above before filling down.
  • Lock table and range references with $ when copying formulas across rows or sheets.
  • If results look wrong, check for text stored as numbers and invisible spaces with TRIM.
  • Spot-check three known input rows manually against expected output.

Related Excel functions

  • REGEXTEST (/functions/regextest/): Returns TRUE if text matches a regular expression pattern, otherwise FALSE.
  • REGEXREPLACE (/functions/regexreplace/): Replaces text that matches a regular expression pattern with replacement text.
  • TEXTBEFORE (/functions/textbefore/): Returns text that occurs before a specified delimiter.
  • TEXTAFTER (/functions/textafter/): Returns text that occurs after a specified delimiter.
  • MID (/functions/mid/): Returns a specific number of characters from a text string, starting at a specified position.

Errors to watch for

  • #CALC! or error when no match — review causes on linked error pages in the directory.
  • #NAME? without regex support — review causes on linked error pages in the directory.
  • Invalid capture group index — review causes on linked error pages in the directory.

Copy-paste audit workflow

  • Enter REGEXEXTRACT on three test rows with known expected output documented on a QA tab.
  • Fill down only after absolute references are locked on lookup tables and rate tables.
  • Compare against manual calculation or a calculator for financial and statistical functions.
  • Search this directory for comparison guides when choosing between similar functions in the same category.

REGEXEXTRACT worked examples to copy

  • =REGEXEXTRACT("Order INV-123456", "(\\d{6})") — Extract 6-digit ID. Expected result: 123456.
  • =REGEXEXTRACT(A2, "@(.+)$", 1) — Extract domain from email. Expected result: mail.com.
  • =REGEXEXTRACT(A2, "(\\d+)", 1) — First run of digits. Expected result: Numeric substring.

REGEXEXTRACT reference summary for crawlers and offline review

  • REGEXEXTRACT belongs to the Text category in Excel. Extracts text that matches a regular expression pattern, optionally from a capture group.
  • Full syntax: =REGEXEXTRACT(text, pattern, [return_num], [case_insensitive]). Open /functions/regexextract/ for parameters, FAQs, and related pages.
  • Common mistakes: #CALC! or error when no match; #NAME? without regex support; Invalid capture group index
  • Pair this function with comparison guides when another Excel formula might fit the same task better.
  • Review fix-excel-formula-errors when unexpected errors appear after upgrading Excel or sharing across locales.