Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

REGEXEXTRACT in Google Sheets: Extract Text with REGEXMATCH and REGEXREPLACE

REGEXEXTRACT in Google Sheets with REGEXMATCH and REGEXREPLACE
Illustration: REGEXEXTRACT in Google Sheets

REGEXEXTRACT in Google Sheets pulls a part of a text out of a cell using a pattern, and its two partners REGEXMATCH and REGEXREPLACE test and change text the same way. They are the tools to use when LEFT, MID and FIND get too long, for example to get an email address, a number or an invoice code out of a messy sentence. This guide explains the three functions with made-up examples and common patterns.

REGEXEXTRACT syntax

=REGEXEXTRACT(text, regular_expression)

The text is the cell to search. The regular expression is a pattern in quotes. Google Sheets uses the RE2 syntax for patterns. REGEXEXTRACT returns the first part of the text that matches. If nothing matches, it returns the #N/A error.

Extract a number from text

If A2 holds "Order 4821 shipped", this formula returns the number:

=REGEXEXTRACT(A2, "\d+")

The \d means a digit and the plus sign means one or more of them. The result is text. To use it in math, wrap it in VALUE.

REGEXEXTRACT in Google Sheets to extract a number from text
Made-up order text (illustration).

Extract an email address

If A2 holds "Contact: [email protected] today":

=REGEXEXTRACT(A2, "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}")

This is a practical pattern that works for most addresses, though it does not cover every rare case.

Extract a part with a capture group

Brackets mark the part to return. To get the code after "INV-":

=REGEXEXTRACT(A2, "INV-(\d+)")

For "INV-2026-045" this returns 2026, the digits that come right after INV-. Without brackets, the result would include the whole match, INV-2026.

REGEXEXTRACT in Google Sheets with a capture group for an invoice code
Brackets mark the part to return (illustration).

REGEXMATCH: test if text matches

=REGEXMATCH(text, regular_expression)

It returns TRUE or FALSE. To check if a cell contains the word "refund", whatever the case:

=REGEXMATCH(A2, "(?i)refund")

The (?i) at the start makes the match case insensitive. REGEXMATCH is useful inside IF, in FILTER and in conditional formatting. For example, =IF(REGEXMATCH(A2, "refund|return"), "Check", "") flags a cell that has either word. The pipe means "or". See our guide to the FILTER function for using it as a condition.

REGEXMATCH in Google Sheets to find a word ignoring case
Returns TRUE or FALSE (illustration).

REGEXREPLACE: change text

=REGEXREPLACE(text, regular_expression, replacement)

To remove everything that is not a digit from a phone number such as "(555) 123-4567":

=REGEXREPLACE(A2, "[^0-9]", "")

The result is 5551234567. The caret inside the brackets means "anything except".

REGEXREPLACE in Google Sheets to remove non-digits from a phone number
Keep digits only (illustration).

Use it on a whole column

Wrap the formula in ARRAYFORMULA to fill a column at once:

=ARRAYFORMULA(REGEXEXTRACT(A2:A100, "\d+"))

If some rows have no match, the column shows #N/A. Hide it with IFERROR. Read ARRAYFORMULA examples for more on this pattern.

A short list of pattern pieces

  • \d is a digit and \w is a letter, digit or underscore.
  • . is any character.
  • + means one or more, * means zero or more, ? means optional.
  • [abc] is one of the listed characters.
  • ^ is the start of the text and $ is the end.
  • ( ) is a group to return.

Common mistakes

  • #N/A. The pattern found nothing. Test with REGEXMATCH first.
  • Numbers as text. REGEXEXTRACT returns text. Use VALUE for math.
  • Several groups. If your pattern has more than one bracket group, the result spills across cells.
  • Missing backslash. A dot or a bracket meant literally needs a backslash in front.
  • Case. Patterns are case sensitive unless you start with (?i).

Questions and answers

Does Excel have REGEXEXTRACT?

Not in all versions. Excel has regular expression functions only in recent Microsoft 365 builds, so check your own version. For older versions, use LEFT, MID and FIND, as in our guide to LEFT, RIGHT and MID.

Can REGEXEXTRACT return all matches?

It returns the first one. To get several, use a pattern with more groups or split the text first.

Is there an easier way to learn the patterns?

Start with digits, letters and one capture group. Build the pattern one piece at a time and test each piece with REGEXMATCH.

Summary

Use REGEXEXTRACT to pull text, REGEXMATCH to test and REGEXREPLACE to clean. Start small, test the pattern and wrap in IFERROR when some rows may not match.

العربية