Intermediate 10 min read

REGEXMATCH, REGEXEXTRACT, REGEXREPLACE

Use REGEXMATCH, REGEXEXTRACT, and REGEXREPLACE in Google Sheets for pattern-based text matching, extraction, and replacement with regular expressions.

SB

Sheets Bootcamp

May 19, 2026

REGEXMATCH, REGEXEXTRACT, and REGEXREPLACE in Google Sheets use regular expressions to match, extract, and replace text based on patterns. The text functions guide covers the full set of text tools, and these three regex functions handle tasks that would require complex combinations of FIND, MID, and SUBSTITUTE.

This guide covers each function’s syntax, the most useful regex patterns, and practical examples using real data.

In This Guide

REGEXMATCH: Test for a Pattern

REGEXMATCH returns TRUE or FALSE based on whether the text matches a regex pattern.

Formula
=REGEXMATCH(text, regular_expression)
ArgumentDescriptionRequired
textThe text string or cell referenceYes
regular_expressionThe regex pattern to test againstYes

Example: =REGEXMATCH("harry.potter@owlmail.com", "@owlmail\.com$") returns TRUE. The pattern checks if the text ends with @owlmail.com.

REGEXMATCH does not extract or modify text. It only checks for a match. Use it inside IF to branch based on patterns: =IF(REGEXMATCH(A2, "^E\d+"), "Employee", "Other").

REGEXEXTRACT: Pull Out Matching Text

REGEXEXTRACT returns the portion of text that matches a regex pattern.

Formula
=REGEXEXTRACT(text, regular_expression)
ArgumentDescriptionRequired
textThe text string or cell referenceYes
regular_expressionThe regex pattern with optional capture groupYes

Example: =REGEXEXTRACT("(555) 123-4567", "\d{3}") returns "555". The pattern \d{3} matches the first group of three consecutive digits.

When you use parentheses (capture groups), REGEXEXTRACT returns only the captured portion:

Formula
=REGEXEXTRACT(B2, "@(.+)")

For "harry.potter@owlmail.com", the pattern matches @owlmail.com, but the capture group returns only owlmail.com (everything inside the parentheses).

REGEXREPLACE: Replace by Pattern

REGEXREPLACE replaces text that matches a regex pattern with new text.

Formula
=REGEXREPLACE(text, regular_expression, replacement)
ArgumentDescriptionRequired
textThe text string or cell referenceYes
regular_expressionThe pattern to matchYes
replacementThe replacement text (use "" to delete)Yes

Example: =REGEXREPLACE("(555) 123-4567", "[^\d]", "") returns "5551234567". The pattern [^\d] matches every non-digit character, and replacing with "" removes them all.

Important

The regex functions are case-sensitive by default. Add (?i) at the start of the pattern for case-insensitive matching. =REGEXMATCH(A2, ”(?i)potter”) matches “POTTER”, “Potter”, and “potter”.

Regex Patterns Step-by-Step

We’ll validate, extract, and clean data from the messy contacts table.

1

Open the contacts spreadsheet

The table has 8 contacts with mixed-case emails in column B and phone numbers in various formats in column C: "(555) 123-4567", "555.987.6543", "555-234-5678".

Messy contacts table for regex examples in Google Sheets

2

Validate email domains with REGEXMATCH

Select cell F2 and enter:

Formula
=REGEXMATCH(B2, "@owlmail\.com$")

The $ anchor matches only at the end of the string. The \. escapes the period to match a literal dot (not any character). For "harry.potter@owlmail.com" (lowercase), this returns TRUE. For "HERMIONE.GRANGER@OWLMAIL.COM" (uppercase), this returns FALSE because the regex is case-sensitive.

REGEXMATCH checking if email addresses contain owlmail domain

To match regardless of case, add (?i):

Formula
=REGEXMATCH(B2, "(?i)@owlmail\.com$")

Now both lowercase and uppercase emails return TRUE.

3

Extract area codes with REGEXEXTRACT

Select cell G2 and enter:

Formula
=REGEXEXTRACT(C2, "\d{3}")

\d{3} matches the first three consecutive digits. Regardless of whether the phone is "(555) 123-4567", "555.987.6543", or "555-234-5678", the area code 555 is always the first three-digit group.

REGEXEXTRACT pulling area code digits from phone numbers

4

Clean phone numbers with REGEXREPLACE

Select cell H2 and enter:

Formula
=REGEXREPLACE(C2, "[^\d]", "")

[^\d] matches any character that is not a digit. Replacing with "" removes all formatting. For any phone format in the data, this returns a clean 10-digit number: 5551234567.

REGEXREPLACE removing all non-digit characters from phone numbers

Note

Compare this to the SUBSTITUTE approach: =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,”(”,""),”)”,""),”-”,""),” ”,"") needs five layers. REGEXREPLACE does it in one.

Essential Regex Patterns

Here are the patterns that cover most Google Sheets use cases:

PatternMatchesExample
\dAny digit (0-9)\d{3} matches “555”
\DAny non-digit\D+ matches ”()” and ”-“
\wWord character (letter, digit, _)\w+ matches “harry”
\sWhitespace (space, tab)\s+ matches ” “
.Any character except newlinea.b matches “a1b”
[abc]Character in set[aeiou] matches vowels
[^abc]Character not in set[^\d] matches non-digits
^Start of string^E matches strings starting with E
$End of string\.com$ matches strings ending in .com
+One or more\d+ matches “123”
*Zero or more\d* matches "" or “123”
?Zero or one\d? matches "" or “5”
{n}Exactly n times\d{3} matches “555”
(...)Capture group@(.+) captures “owlmail.com”
(?i)Case-insensitive flag(?i)hello matches “HELLO”

Practical Examples

Example 1: Extract Domain from Email

Use a capture group to get everything after the @ symbol:

Formula
=REGEXEXTRACT(B2, "@(.+)")

For "harry.potter@owlmail.com", the capture group returns owlmail.com. The @ is part of the match but not the capture.

REGEXEXTRACT using capture group to extract domain from email

Example 2: Validate Phone Number Format

Check if a phone number has exactly 10 digits (after stripping formatting):

Formula
=REGEXMATCH(REGEXREPLACE(C2, "[^\d]", ""), "^\d{10}$")

The inner REGEXREPLACE strips all non-digits. The outer REGEXMATCH checks if the result is exactly 10 digits. Returns TRUE for valid phone numbers, FALSE for ones with too few or too many digits.

Example 3: Extract First Name from Mixed-Case Names

Pull the first word (letters only) from names with extra spaces:

Formula
=REGEXEXTRACT(TRIM(A2), "^\w+")

^\w+ matches one or more word characters from the start of the string. For "HARRY POTTER" (after TRIM), this returns HARRY. Combine with PROPER to get Harry: =PROPER(REGEXEXTRACT(TRIM(A2), "^\w+")).

Example 4: Format Phone Numbers

Insert formatting into clean digit strings:

Formula
=REGEXREPLACE(REGEXREPLACE(C2, "[^\d]", ""), "(\d{3})(\d{3})(\d{4})", "($1) $2-$3")

The three capture groups grab the area code, exchange, and line number. The replacement string formats them as (555) 123-4567. This normalizes any phone format to a consistent US format.

Common Errors and How to Fix Them

#VALUE! Error: No Match Found

REGEXEXTRACT returns #VALUE! when the pattern does not match any text in the cell. Wrap in IFERROR: =IFERROR(REGEXEXTRACT(A2, "\d+"), "No digits").

REGEXMATCH does not have this problem — it returns FALSE instead of erroring.

#VALUE! Error: Invalid Regular Expression

A malformed regex pattern causes a #VALUE! error. Common mistakes:

  • Unescaped special characters: use \. for a literal period, not .
  • Unmatched parentheses or brackets
  • Invalid quantifiers like {3,1} (max must be >= min)

#REF! Error from Multiple Capture Groups

REGEXEXTRACT with multiple capture groups returns multiple columns. If the cells to the right are occupied, it returns #REF!. Clear the adjacent cells or use a single capture group.

Tip

Test your regex patterns on a single cell before applying to a full column. Complex patterns with subtle bugs are hard to debug across 100+ rows.

Tips and Best Practices

  1. Start with REGEXMATCH for validation. Before extracting or replacing, test the pattern with REGEXMATCH to confirm it matches the text you expect.

  2. Use (?i) for case-insensitive patterns. Place it at the start of the pattern. (?i)@owlmail\.com$ matches emails regardless of case.

  3. Escape special characters with a backslash. Periods (.), parentheses (()), brackets ([]), and other regex metacharacters need a \ prefix to match literally.

  4. Use REGEXREPLACE for cleaning tasks. =REGEXREPLACE(A2, "[^\d]", "") is cleaner than nesting five SUBSTITUTE calls to remove individual characters.

  5. Capture groups control what REGEXEXTRACT returns. Without parentheses, it returns the full match. With parentheses, it returns only the captured portion. Use this to exclude parts of the match you do not need.

Frequently Asked Questions

What is REGEXMATCH in Google Sheets?

REGEXMATCH tests whether a text string matches a regular expression pattern and returns TRUE or FALSE. For example, =REGEXMATCH(A2, "^[0-9]+$") returns TRUE if the cell contains only digits. It is useful for data validation and conditional checks.

How do I extract text with a pattern in Google Sheets?

Use REGEXEXTRACT. =REGEXEXTRACT(A2, "pattern") returns the portion of text that matches the pattern. Use capture groups (parentheses) to specify exactly which part to return. For example, =REGEXEXTRACT(B2, "@(.+)") extracts the domain from an email address.

How do I remove all non-numeric characters in Google Sheets?

Use =REGEXREPLACE(A2, "[^0-9]", ""). The pattern [^0-9] matches any character that is not a digit. Replacing with an empty string removes them all. This is cleaner than nesting multiple SUBSTITUTE calls for different characters.

Are Google Sheets regex functions case-sensitive?

Yes, by default. REGEXMATCH, REGEXEXTRACT, and REGEXREPLACE are case-sensitive. Add (?i) at the start of the pattern for case-insensitive matching. For example, =REGEXMATCH(A2, "(?i)potter") matches “POTTER”, “Potter”, and “potter”.

What regex syntax does Google Sheets use?

Google Sheets uses RE2 syntax, which is a subset of standard regex. It supports character classes [a-z], quantifiers (+, *, ?), anchors (^, $), groups (), alternation (|), and most common patterns. It does not support lookaheads, lookbehinds, or backreferences.

Frequently Asked Questions

Next Steps

Continue learning with these related tutorials: