Replace everything matching a pattern in one move. REGEXREPLACE strips non-digits, collapses spaces, or reformats text far more powerfully than nested SUBSTITUTE.
[^0-9] matches any non-digit; replacing it with "" leaves only the numbers — perfect for cleaning phone numbers.
The example
Reduce a formatted phone number to raw digits.
| A | B | |
|---|---|---|
| 1 | Text | Cleaned |
| 2 | (555) 123-4567 | 5551234567 |
The formula
Replace all matches at once:
How it works
One pattern replaces many things:
- The pattern describes what to replace; the third argument is the replacement.
[^0-9]means “any character that is not a digit” — the caret inside brackets negates the set.- Replacing with
""deletes those characters; replace with a space or text to transform instead. - 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
Replace pattern matches with the replacement.
Variations
Collapse spaces
Multiple spaces → one:
Swap name order
Groups in the replacement:
Remove letters
Keep non-letters:
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
Frequently asked questions
How do I strip all non-numeric characters in Excel?
How do I reorder text like Last, First to First Last?
Does REGEXREPLACE replace all matches or just the first?
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