Skip to content
ExcelExcel Microsoft 365+

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.

  1. Keep only the digits of a phone number:

    =REGEXREPLACE(A2, "[^0-9]", "")

    Result"4915112345678"

  2. 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.

Loading the editor…