Wauvel

Excel like a finance pro.

← The library

Text function

REGEXREPLACE

Replaces text matching a regular expression.

OccasionalDifficulty 1550 · AdvancedUsage rank #233 of 520
Practice · 3 questions →

When to use it

Replaces text matching a regular expression, with $1-style references to capture groups.

The shape of it

Syntax
=REGEXREPLACE(text, pattern, replacement, ...)

Worked examples

  • Digits only

    =REGEXREPLACE("555-123-4567","\D","") 5551234567

    Remove every non-digit.

  • Collapse spaces

    =REGEXREPLACE("a b c","\s+"," ") a b c

    Collapse whitespace.

  • Reorder with groups

    =REGEXREPLACE("Ekelund, Blake","(\w+), (\w+)","$2 $1") Blake Ekelund

    Swap the two captured words.

Worth knowing

  • Occurrence 0 (default) replaces all; a positive number replaces only that match.
  • Clean phone numbers, SKUs, and addresses in one pass instead of chained SUBSTITUTEs.
  • Requires Microsoft 365 (2024).

Where it goes wrong

  • A pattern that matches empty strings can insert the replacement everywhere.
  • #VALUE! for an invalid pattern.

Related

Learn the moves here — or let Wauvel run them on your numbers.

Meet your AI CFO →

One CFO-grade Excel tip a week

A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.