Category: FUNCTION | Updated: 2026-11-22

How to Use the REGEXEXTRACT Function in Google Sheets | Extract Specific Text with Regular Expressions

How to Use the REGEXEXTRACT Function

The REGEXEXTRACT function is a Google Sheets text function that extracts the first substring matching a specified regular expression pattern from a given text string.

Syntax

=REGEXEXTRACT(text, regular_expression)
  • text: The input text string or cell reference (e.g., A2) from which to extract text (required).
  • regular_expression: The regular expression pattern to match, enclosed in double quotation marks (") (required).

Examples

Here are examples of extracting specific substrings (such as numbers or postal codes) from order and contact data.

Row Column A (Source Data) Column B (Extracted Result) Formula Used
1 Source Data Extracted Result Formula Used
2 Order No.: ORD-20261122 20261122 =REGEXEXTRACT(A2, "[0-9]+")
3 060-0001 Sapporo, Hokkaido 060-0001 =REGEXEXTRACT(A3, "[0-9]{3}-[0-9]{4}")
4 Staff: Yamada (Sales) Sales =REGEXEXTRACT(A4, "\((.+)\)")
5 ID: user_abc@example.com user_abc =REGEXEXTRACT(A5, "ID: ([a-zA-Z0-9_]+)")
  • Formula in B2: =REGEXEXTRACT(A2, "[0-9]+") → Extracts the consecutive digits 20261122.
  • Formula in B4: =REGEXEXTRACT(A4, "\((.+)\)") → Uses the capture group () to extract only Sales from inside the parentheses.

Common Errors and Tips

  • Returns #N/A if no match is found: If the specified regular expression does not match anything in the text, #N/A is returned. To display a blank or fallback value instead of an error, wrap it with IFERROR, such as =IFERROR(REGEXEXTRACT(A2, "[0-9]+"), "").
  • Referencing a numeric cell directly may cause #VALUE!: REGEXEXTRACT is strictly for text strings. If the target cell contains a number, append &"" (e.g., A2&"") or convert it using the TO_TEXT function.
  • Only the first match is returned: Even if the pattern appears multiple times in the text, the function only returns the first matching occurrence (if multiple capture groups are specified, each group is output across adjacent columns).

Frequently Asked Questions

Q. Why does the extracted result change when I use parentheses () in REGEXEXTRACT?

A. In regular expressions, parentheses () act as a capture group, meaning only the portion matching the pattern inside the parentheses is extracted. If you want to match literal parentheses characters, escape them with backslashes like \( and \).

Q. Why do I get an error when using REGEXEXTRACT on a cell containing a number?

A. REGEXEXTRACT only works on text strings, so referencing a pure numeric or date value directly can return a #VALUE! error. To process a number, convert it to text first, such as "=REGEXEXTRACT(A2&"", "[0-9]+")".