# REGEXEXTRACT

## Content

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**

| @cols=1:**Argument** | @cols=1:**Description** |
| -------- | ----------- |
| @cols=1:@rows=1:*text* | @cols=1:@rows=1:[Required] The input text or a cell reference containing the text to extract from. |
| @cols=1:@rows=1:*pattern* | @cols=1:@rows=1:[Required] The regular expression defining the pattern to match. |
| @cols=1:@rows=1:*return\_mode* | @cols=1:@rows=1:[Optional] Specifies the extraction mode:<br>​​**0**​​ – Returns the first match(Default)<br>​​**1**​​ – Returns all matches as an array<br>​​**2**​​ – Returns capturing groups from the first match as an array<br>Note: Capturing groups are regex subpatterns enclosed in parentheses (...), allowing extraction of specific match segments. |
| @cols=1:@rows=1:*case\_sensitivity* | @cols=1:@rows=1:[Optional] Controls case sensitivity:<br>​​**0**​​ – Case-sensitive(Default)<br>​​**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.