Clean Text with REGEXREPLACE

Excel Formulas › Advanced

365 (2024+)REGEX

Replace everything matching a pattern in one move. REGEXREPLACE strips non-digits, collapses spaces, or reformats text far more powerfully than nested SUBSTITUTE.


Quick formula: strip everything except digits from A2:
=REGEXREPLACE(A2, "[^0-9]", "")
[^0-9] matches any non-digit; replacing it with "" leaves only the numbers — perfect for cleaning phone numbers.

Functions used (tap for the full reference guide):

The example

Reduce a formatted phone number to raw digits.

AB
1TextCleaned
2(555) 123-45675551234567

The formula

Replace all matches at once:

=REGEXREPLACE(A2, "[^0-9]", "") // keep digits only

How it works

One pattern replaces many things:

  1. The pattern describes what to replace; the third argument is the replacement.
  2. [^0-9] means “any character that is not a digit” — the caret inside brackets negates the set.
  3. Replacing with "" deletes those characters; replace with a space or text to transform instead.
  4. Use capture groups in the replacement ($1) to reorder — e.g. swap “Last, First” to “First Last.”

Reorder with groups: =REGEXREPLACE(A2, "(\w+), (\w+)", "$2 $1") turns “Smith, Jane” into “Jane Smith.” That kind of swap is painful with SUBSTITUTE but trivial with regex.

Try it: interactive demo

Live demo

Replace pattern matches with the replacement.

Result:

Variations

Collapse spaces

Multiple spaces → one:

=REGEXREPLACE(A2, "\s+", " ")

Swap name order

Groups in the replacement:

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

Remove letters

Keep non-letters:

=REGEXREPLACE(A2, "[A-Za-z]", "")

Pitfalls & errors

365 (2024+) only. Older Excel lacks REGEXREPLACE — nest SUBSTITUTE instead.

Global by default. REGEXREPLACE replaces all matches. Anchor or narrow the pattern if you only want some.

Replacement uses $1, $2. Reference capture groups with $1 in the replacement string, not \1.

Practice workbook

📊
Download the free Clean Text with REGEXREPLACE practice workbook
REGEXREPLACE examples (formula text + result) with collapse-spaces, name-swap, and remove-letters variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I strip all non-numeric characters in Excel?
Use =REGEXREPLACE(A2, "[^0-9]", "") to remove everything that is not a digit, leaving the raw number. Requires Excel 365 (2024+).
How do I reorder text like Last, First to First Last?
Use capture groups: =REGEXREPLACE(A2, "(\w+), (\w+)", "$2 $1") swaps the two parts.
Does REGEXREPLACE replace all matches or just the first?
All matches by default. Narrow or anchor the pattern if you want to limit it.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: REGEXEXTRACT · Find & replace several things · Remove specific characters

Function references: REGEXREPLACE