REGEXREPLACE
Short answer
Clean any pattern out of text
REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])
- Category
- Text & Data Cleanup
- Excel version
- 365
- Also searched as
- remove currency symbols, numbers stored as text, regex replace excel, strip non-numeric characters, convert parentheses to negative
What it returns
REGEXREPLACE finds every part of a string that matches a regular expression and replaces it with the text you supply. The result is always text.
=REGEXREPLACE("$1,234.50", "[$,]", "") returns 1234.50. The character class [$,] matches either symbol, and an empty replacement deletes them. =REGEXREPLACE("USD 1,234.50", "[^0-9.]", "") returns the same, because [^0-9.] matches anything that is not a digit or a dot.
That second form is the useful one. You stop listing every bad character and list the good ones instead.
The replacement can reuse what the pattern captured. Parentheses mark a group, and $1 in the replacement puts that group back. =REGEXREPLACE("(1234.50)", "^\((.*)\)$", "-$1") returns -1234.50.
If nothing matches, the original text comes back unchanged. REGEXREPLACE is a Microsoft 365 function. It is not in Excel 2024 or any perpetual version.
Arguments that matter
| Argument | Required | What it does |
|---|---|---|
text | Yes | The string to clean. A cell, or a column, in which case the results spill. |
pattern | Yes | What to find. "[^0-9.]" is any character that is not a digit or a dot. |
replacement | Yes | What to put in its place. "" deletes. $1, $2 insert capture groups. |
occurrence | No | 0 replaces every match (default). A positive number replaces only that match. Negative counts from the end. |
case_sensitivity | No | 0 case-sensitive (default). 1 case-insensitive. |
occurrence defaults to every match, which is right for stripping characters. Set it when only one instance should change, such as the last hyphen in a code with -1.
replacement with group references is what SUBSTITUTE cannot do. SUBSTITUTE swaps fixed text for fixed text. REGEXREPLACE can rearrange: move a trailing minus sign to the front, or turn 31.01.2026 into 2026-01-31.
In a financial model
Exported amounts arrive as text more often than anyone would like. Currency codes, thousands separators, accounting parentheses, a trailing minus sign from an older ERP, non-breaking spaces from a web report. None of them add up. SUMIFS treats them as zero and says nothing.
For a recurring load, clean the column in Power Query, per transform in Power Query, not in cells. REGEXREPLACE is for the working tab, the one-off reconciliation, and the extract someone emails you at 6pm.
Either way the raw column stays as delivered, per raw data stays raw. The cleaned value goes in a new column. Then a check proves it: count the cleaned values that still are not numbers, and put that count in the check row, as build a check row and make it loud describes.
Worked example
A bank or sub-ledger export pasted to a Table named Export, with a text column AmountText:
| AmountText | Amount |
|---|---|
| $1,234.50 | 1234.50 |
| (2,100.00) | -2100.00 |
| USD 845.10 | 845.10 |
| 3,000.00- | -3000.00 |
Four formats, one formula, as a calculated column Amount:
=LET(
raw, [@AmountText],
kept, REGEXREPLACE(raw, "[^0-9.()\-]", ""),
paren, REGEXREPLACE(kept, "^\((.*)\)$", "-$1"),
trail, REGEXREPLACE(paren, "^(.*)-$", "-$1"),
--trail
)
Step one deletes everything except digits, dots, parentheses and hyphens. That removes the $, the USD, the commas and any stray spaces. Step two turns a value wrapped in parentheses into a negative. Step three moves a trailing minus to the front. The double negative converts the text to a number. LET names each step so a reviewer can follow it.
The check, in the check row:
=SUMPRODUCT(--NOT(ISNUMBER(Export[Amount])))
Expected zero. Any row that failed to convert shows #VALUE! in the Amount column and is counted here.
Old way vs new way
The old way, which handles symbols but not parentheses or trailing minus signs:
=--SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE([@AmountText],"$",""),",",""),"USD",""),CHAR(160),"")
The new way, for the same job:
=--REGEXREPLACE([@AmountText], "[^0-9.\-]", "")
Each new symbol meant another SUBSTITUTE layer. The character class keeps what is allowed, so a currency code nobody planned for is removed without a change to the formula.
Where it breaks
The cleaned amount is a thousand times too small. The export uses a decimal comma, 1.234,50, and the pattern keeps the dot and drops the comma, giving 1.23450. Fix: confirm the export’s number format first. For decimal-comma files, delete the dots and turn the comma into a dot, or import with the right locale in Power Query.
A small amount turns into a fraction. A label with a dot, such as Rs. 1,200, leaves .1200 after cleaning, which converts to 0.12. Fix: remove known labels before the character class, or anchor the pattern on the digits.
The result still will not add. REGEXREPLACE always returns text, so 1234.50 sits in the cell as text and SUMIFS ignores it. Fix: convert with -- or VALUE as the last step, and prove it with the ISNUMBER check.
Negatives come out positive. The character class deleted the parentheses before the negative step ran, or the export uses a format you did not handle, such as CR. Fix: keep (, ) and - in the class, convert them in the next step, and test each format in the source.
#SPILL! when pointed at a column. Inside a Table, use [@AmountText] so each row returns one value. Fix: use the row reference, or move the formula outside the Table.
#NAME? on another machine. REGEXREPLACE is Microsoft 365 only. Fix: if the file has to open in Excel 2024 or earlier, clean the column in Power Query at load.
Related functions
- REGEXTEST. Flags the rows a cleanup has not fixed, or validates codes after cleaning.
- REGEXEXTRACT. Pulls the value out instead of deleting what surrounds it. Better when the number sits inside a sentence.
- LET. Names each cleaning step so a chain of replacements stays readable.
- SUMIFS. Where the cleaned amounts go. It ignores text, which is why the conversion and the check matter.
- SUBSTITUTE. Still the simpler tool for one fixed string, such as CHAR(160), in a file that has to open in older Excel.
