Syntax
=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])Arguments
| Argument | Required | Description |
|---|---|---|
text | Required | The text to search |
pattern | Required | The regular expression |
return_mode | Optional | 0 first match (default), 1 all matches, 2 the capture groups of the first match |
case_sensitivity | Optional | 0 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 =REGEXEXTRACT("Order 123 and 456", "[0-9]+", 1)Result Spilled result
| A | |
|---|---|
| 1 | 123 |
| 2 | 456 |
=REGEXEXTRACT("John Smith", "(\w+) (\w+)", 2)Result Spilled result
| A | B | |
|---|---|---|
| 1 | John | Smith |
Related text functions
- MIDBSame as MID, counting bytes; without a double byte language set as default each character counts as one byte.
- NUMBERVALUEConverts text to a number using the decimal and group separators you give, whatever the locale.
- PHONETICReturns the phonetic (furigana) text of a cell; here that is the text of the cell itself.
- PROPERCapitalizes the first letter of each word and makes the other letters lowercase.
- REGEXMATCHChecks whether any part of a text matches a regular expression pattern (case sensitive).
- REGEXREPLACEReplaces the parts of a text that match a regular expression pattern.
- REGEXTESTChecks whether any part of a text matches a regular expression pattern.
- REPLACEReplaces part of a text, given a start position and a number of characters, with other text.
- REPLACEBSame as REPLACE, counting bytes; without a double byte language set as default each character counts as one byte.