Skip to main content

REGEXEXTRACT

Extracts text from a string using a regular expression: the whole match, its capture groups, or every match.

Syntax​

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

Arguments​

  • text: The text or reference to a cell containing the text to extract from.
  • pattern: The regular expression to match against.
  • return_mode: [Optional] 0 (default) returns the whole first match. 1 returns the pattern's capture groups from the first match, as an array (falls back to the whole match if the pattern has no capture groups). 2 returns every whole match found in text, as an array.
  • case_sensitivity: [Optional] TRUE (default) matches case-sensitively. Pass FALSE for a case-insensitive match.

Example​

REGEXEXTRACT("order #4821", "[0-9]+") → Returns "4821"
REGEXEXTRACT("CLM-2026-09", "CLM-(\d+)-(\d+)") → Returns "CLM-2026-09" (return_mode 0, the whole match)
REGEXEXTRACT("CLM-2026-09", "CLM-(\d+)-(\d+)", 1) → Returns ["2026", "09"] (the capture groups)
REGEXEXTRACT("a1 b22 c333", "[0-9]+", 2) → Returns ["1", "22", "333"] (every match)

Usage Notes:

  • Returns "" (return_mode 0) or [] (return_mode 1 or 2) when nothing matches or the pattern is invalid, instead of erroring out the formula.
  • return_mode 1 only returns an array when the pattern actually has capture groups. A pattern with no groups behaves the same as return_mode 0.
  • Regular expressions are JavaScript-flavored (ECMAScript), which covers the vast majority of common patterns but is not identical to Excel's PCRE2 flavor for advanced features like some POSIX character classes.
  • See REGEXTEST to just check for a match, and REGEXREPLACE to replace it.