🔤 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
| Name | Required | Description |
|---|---|---|
| text | Required | String to operate on. |
| regular_expression | Required | RE2 pattern. |
| replacement | Required | Replacement. 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
- SUBSTITUTE — Literal string.
- TRIM + CLEAN — Whitespace 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
REGEXEXTRACT
Extracts the first substring of text matching a regular expression. The Swiss army knife of text par...
REGEXMATCH
Returns TRUE if a string matches a regex pattern, FALSE otherwise. The boolean version of REGEXEXTRA...
SUBSTITUTE
Replaces specified text with new text, optionally only the Nth occurrence. Find-and-replace without ...
CONCATENATE
Joins multiple text values into one string. The classic way to combine fields, but TEXTJOIN is usual...
FIND
Returns position of one string in another, case-sensitively....
Frequently Asked Questions
Capture groups?
Yes — $1, $2, etc. $0 is the whole match.
Escape characters?
Backslash, doubled in formula. Literal period: \\.