REGEXREPLACE Function in Excel: Find and Replace With Patterns

⏱ 1 min readUpdated 28 September 2026

TextLevel: ExpertAvailable in: Excel 365 / 2021+

In this article
  1. Syntax
  2. Examples
  3. Example 1
  4. Example 2
  5. Related functions

REGEXREPLACE replaces text matching a pattern — strip every non-digit, collapse repeated spaces, mask numbers.

Syntax

=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])
Argument What it means
replacement Can use $1, $2 for captured groups.

Examples

Example 1

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

Keep digits only.

Example 2

=REGEXREPLACE(A2, "\d(?=\d{4})", "X")

Mask all but the last four digits.

SUBSTITUTE · REGEXEXTRACT

📚 Part of the free Excel course: Beginner → Expert · Try it in the Formula Lab or ask the AI Helper.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong