1. Home
  2. Functions
  3. Text
  4. REGEXEXTRACT

REGEXEXTRACT function

Returns the parts of a text that match a regular expression pattern.

Syntax

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

Arguments

ArgumentRequiredDescription
textRequiredThe text to search
patternRequiredThe regular expression
return_modeOptional0 first match (default), 1 all matches, 2 the capture groups of the first match
case_sensitivityOptional0 match case (default), 1 ignore case

How to use REGEXEXTRACT

When REGEXEXTRACT returns more than one value, the result spills into the cells below and to the right. Keep those cells empty, or you get #SPILL!.

REGEXEXTRACT takes 2 required arguments and 2 optional arguments. Type =REGEXEXTRACT( in a cell and SheetsBat shows the arguments as you go. Optional arguments are shown in square brackets; leave them out to use their default.

Examples

Each result below was calculated by the SheetsBat formula engine.

=REGEXEXTRACT("Order 123 and 456", "[0-9]+")Result "123"
=REGEXEXTRACT("Order 123 and 456", "[0-9]+", 1)Result 2 by 1 array
Spilled result
A
1123
2456
=REGEXEXTRACT("John Smith", "(\w+) (\w+)", 2)Result 1 by 2 array
Spilled result
AB
1JohnSmith

Every formula, right in your browser

SheetsBat calculates 536 functions, with charts, pivot tables and live collaboration. Free to start.