Skip to main content
SheetCraft
🔤 Text Function · advanced

REGEXREPLACE Function in Google Sheets

Replaces text matching a regex pattern with a substitution. Regex version of SUBSTITUTE.

Syntax

REGEXREPLACE(text, regular_expression, replacement)

Returns: text with all matches replaced.

Excel equivalent: No direct equivalent.

Parameters

NameRequiredDescription
textRequiredString to operate on.
regular_expressionRequiredRE2 pattern.
replacementRequiredReplacement. Can reference capture groups with $1, $2.

Examples

Strip non-digits

=REGEXREPLACE(A2, "\\D", "")

Normalize phone numbers.

Standardize whitespace

=REGEXREPLACE(A2, "\\s+", " ")

Collapses whitespace runs to single space.

Reorder name

=REGEXREPLACE(A2, "(\\w+)\\s+(\\w+)", "$2, $1")

First Last → Last, First.

When to use an alternative

  • SUBSTITUTELiteral string.
  • TRIM + CLEANWhitespace only.

Common errors and how to fix them

  • Backslash escaping

    Cause: Need \\ in formula strings.

    Fix: Double every backslash.

  • Pattern not supported

    Cause: Non-RE2 feature.

    Fix: RE2-supported syntax only.

Related functions

Frequently Asked Questions

Capture groups?

Yes — $1, $2, etc. $0 is the whole match.

Escape characters?

Backslash, doubled in formula. Literal period: \\.

Source: Google Sheets official function reference.