
TextLevel: ExpertAvailable in: Excel 365 / 2021+
In this article
- Syntax
- Examples
- Example 1
- Example 2
- 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 articleStuck on a step? Ask a question and the AI answers using this article.
Free · AI can be wrong