REGEXEXTRACT
Extract the part of a string that matches a regular expression — the first match, every match, or the capture groups.
Syntax
REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity]) | Argument | Required | Description |
|---|---|---|
text | Required | The text to search. |
pattern | Required | A regular expression. |
return_mode | Optional | 0 (the default) for the first match, 1 for every match, 2 for the capture groups of the first match. 1 and 2 spill across a row. |
case_sensitivity | Optional | 0 (the default) for case-sensitive matching, 1 to ignore case. |
Examples
Every example below was executed against VisiGrid engine 0.54.0 — not
transcribed from another vendor's documentation. Reproduce any of them with vgrid calc.
| Formula | Result | Notes |
|---|---|---|
=REGEXEXTRACT(A2,"\d{3}-\d{4}") | 555-1234 | The first phone number. |
=D1 | 555-9876 | With return_mode 1 in C1, every match spills across C1:D1. |
=G1 | example | With return_mode 2 in F1, the two capture groups spill across F1:G1 — "ana" and "example". |
=REGEXEXTRACT("no digits","\d+") | #N/A | No match is #N/A, which IFNA can catch. |
The result is text
Everything REGEXEXTRACT returns is text, including digits. Wrap it in
VALUE to use an extracted number in arithmetic.
When nothing matches
A missing match is #N/A, so a column with some rows lacking the pattern shows
errors. IFNA turns them into something readable:
=IFNA(REGEXEXTRACT(A2,"\d+"),"")
Capture groups
Parentheses in the pattern mark groups. Return mode 2 returns each group of the first match in its own cell — a way to split a string into parts in one step, such as the user and domain of an email address.
Simpler tools
For text before or after a fixed delimiter, TEXTBEFORE
and TEXTAFTER are easier to read than a pattern.
Excel compatibility
Matches Excel's REGEXEXTRACT, including #N/A for no match and the three return modes. Excel uses PCRE2; lookaround and backreferences are not supported here and return #VALUE!.