REGEXREPLACE function in Excel
Replaces strings within the provided text that matches the pattern with replacement
=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])REGEXREPLACE syntax and parameters
Five arguments, three required.
- textstringRequired
The text or the reference to a cell containing the text you want to replace strings within.
- patternstringRequired
The regular expression ("regex") that describes the pattern of text you want to replace.
- replacementstringRequired
The text you want to replace instances of pattern.
- occurrencenumberOptional
Specifies which instance of the pattern you want to replace. By default, occurrence is 0, which replaces all instances. A negative number replaces that instance, searching from the end.
- case_sensitivitynumberOptional
Determines whether the match is case-sensitive. By default, the match is case-sensitive. Enter one of the following:0: Case sensitive1: Case insensitive
REGEXREPLACE examples
Formulas you'll actually reuse.
Keep only the digits of a phone number:
=REGEXREPLACE(A2, "[^0-9]", "")Result
"4915112345678"Collapse runs of whitespace (tabs, doubled spaces) into one space:
=REGEXREPLACE(A2, "\s+", " ")
REGEXREPLACE in Google Sheets
Same name — your formula ports as-is.
Try REGEXREPLACE in the playground
Edit the example — nothing to install.
Preloaded with the REGEXREPLACE formula from Example 1 — change anything and watch it respond.
Related functions
More ways Excel gets this done.
- ARRAYTOTEXTReturns an array of text values from any specified rangeTextNo Google Sheets equivalent
- CHARReturns the character specified by the code numberTextGoogle Sheets
- CLEANRemoves all nonprintable characters from textTextGoogle Sheets
- CODEReturns a numeric code for the first character in a text stringTextGoogle Sheets
- CONCATCombines the text from multiple ranges and/or strings, but it doesn't provide the delimiter or IgnoreEmpty arguments.TextGoogle Sheets
- CONCATENATEJoins several text items into one text itemTextGoogle Sheets