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
Put 212-555-0198 in A2:
=REGEXREPLACE(A2,"^[0-9]+-","***-")ExcelThe result is ***-555-0198. The ^ requires the digit group to begin at the start of this single-line value. Without it, the pattern also matches 555-, and the default all-matches replacement produces ***-***-0198.
Reorder first and last names with capture groups
For this separate example, put MayaLopez in A2:
=REGEXREPLACE(A2,"([A-Z][a-z]+)([A-Z][a-z]+)","$2, $1")ExcelThe result is Lopez, Maya. The parentheses capture Maya and Lopez separately; $2 and $1 put those groups in the opposite order. This example assumes two adjacent names, each starting with one uppercase ASCII letter followed by lowercase ASCII letters. It isn't a general rule for names with spaces, punctuation, or other capitalization.
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.
With A2 set back to 212-555-0198, you can choose a single match without anchoring the pattern:
=REGEXREPLACE(A2,"[0-9]+-","***-",1)FormulaThis returns ***-555-0198. Changing the final argument to -1 replaces the last match and returns 212-***-0198. Positive positions count from the start; negative positions count from the end. Microsoft's REGEXREPLACE reference documents these occurrence rules and the PCRE2 pattern syntax.
Case sensitivity uses numeric flags
By default the match is case-sensitive. Use the optional argument when you want a case-insensitive replacement.