[]
        
(Showing Draft Content)

REGEXEXTRACT

The REGEXEXTRACT function extracts text from a string based on a specified regular expression. It supports extracting the first match, all matches, or capturing groups from the first match.

Syntax

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

Arguments

Argument

Description

text

[Required] The input text or a cell reference containing the text to extract from.

pattern

[Required] The regular expression defining the pattern to match.

return_mode

[Optional] Specifies the extraction mode:

​​0​​ – Returns the first match(Default)

​​1​​ – Returns all matches as an array

​​2​​ – Returns capturing groups from the first match as an array

Note: Capturing groups are regex subpatterns enclosed in parentheses (...), allowing extraction of specific match segments.

case_sensitivity

[Optional] Controls case sensitivity:

​​0​​ – Case-sensitive(Default)

​​1​​ – Case-insensitive

Example

REGEXEXTRACT("10 apples, 12 oranges","[0-9]+") gives the result 10

REGEXEXTRACT("10 apples, 12 oranges","[0-9]+", 1) gives the result [10, 12]

REGEXEXTRACT("09/12/1998 from James","\d{1,2}/\d{1,2}/\d{2,4}\b") gives the result 09/12/1998

REGEXEXTRACT("Sonia (378) 555-4195","\d{3}-\d{4}") gives the result 555-4195

REGEXEXTRACT("O my Luve red rose", "O my (\w+) red (\w+)") gives the result O my Luve red rose

REGEXEXTRACT("O my Luve red rose", "O my (\w+) red (\w+)", 2) gives the result["Luve", "rose"]

Version Available

This function is available in product version 19.0 or later.