FormulaCamp
Completed
← Google Sheets functions
Google Sheets function

REGEXREPLACE in Google Sheets

Google Sheets REGEXREPLACE takes exactly three arguments: the text, the regular expression and the replacement.

In Google Sheets

It uses RE2 syntax, which has no lookahead or lookbehind, and the same family includes REGEXMATCH and REGEXEXTRACT.

The arguments and common errors are covered in the REGEXREPLACE Excel guide; check the function help in Google Sheets for its own argument list.

Worked examples in Google Sheets

Keep only the digits

A
1Phone
2(415) 555-0100

Formula: C2: =REGEXREPLACE(A2,"\D","")

Result: 4155550100

The backslash-D class means any non-digit; replacing it with nothing removes it.

Collapse repeated spaces

A
1Text
2a b c

Formula: C2: =REGEXREPLACE(A2,"\s+"," ")

Result: a b c

Every run of whitespace becomes one space.

Swap with groups

A
1Name
2Lee, Ana

Formula: C2: =REGEXREPLACE(A2,"(\w+), (\w+)","$2 $1")

Result: Ana Lee

The two captured words are written back in reverse order.

Try it

A tiny spreadsheet with example data. Edit the formula or any number and see the result.

Formula in D2: =REGEXREPLACE(A4,"\s+"," ")

Example spreadsheet for REGEXREPLACE
ABCD
1TextOtherResult
2Alice Johnsonalice johnson extra spaces
3[email protected][email protected]
4 extra spaces
5SKU-2026-0415
6iced coffee, tea, sugar
7Order 417 shipped
Result in D2: extra spaces
Practice this in a lesson: REGEX Functions

Frequently asked questions

Why does REGEXREPLACE fail with more than three arguments in Google Sheets?
Sheets accepts only the text, the pattern and the replacement. The optional occurrence and case-sensitivity arguments belong to the Excel version.
Can REGEXREPLACE use lookahead in Google Sheets?
No. It runs on RE2, which leaves out lookahead and lookbehind; rewrite the pattern with groups instead.

Google Sheets is used here only as a descriptive product name. FormulaCamp is not affiliated with Google.