Back to functions
Text2026-06-130 related articles

REGEXREPLACE Function in Excel

Replace matching text in a string by using a regular expression pattern.

Syntax

REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])

Arguments

text

Required

The text or cell reference containing the text you want to search within.

pattern

Required

The regular expression pattern that defines what text to match.

replacement

Required

The text that should replace each matched pattern.

occurrence

Optional

Which occurrence to replace. By default Excel uses 0, which replaces all matches.

case_sensitivity

Optional

Controls case-sensitive matching. Use 0 for case-sensitive and 1 for case-insensitive.

What it returns

Returns the updated text after replacing matches defined by the regex pattern.

What REGEXREPLACE does

REGEXREPLACE replaces text inside a string based on a regular expression pattern. It is useful when simple find-and-replace logic is not flexible enough and you need pattern-based cleanup.

Practical examples

Mask the first part of a phone number

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

This replaces the leading digit group and keeps the rest of the string unchanged.

Reorder first and last names with capture groups

=REGEXREPLACE(A2,"([A-Z][a-z]+)([A-Z][a-z]+)","$2, $1")

This uses capture groups to rearrange matched parts of the text.

Common mistakes and notes

REGEXREPLACE is available only in newer Excel builds

Microsoft lists this function only for Excel for Microsoft 365 and Excel for Microsoft 365 for Mac.

Occurrence defaults to all matches

If you omit occurrence, Excel uses 0, which means every match is replaced rather than only the first one.

Case sensitivity uses numeric flags

By default the match is case-sensitive. Use the optional argument when you want a case-insensitive replacement.

Related functions

Official documentation