# REGEXREPLACE formula generator

> Describe what you need and get a REGEXREPLACE formula for Excel and Google Sheets, run on real data before you copy it. Plus 8 tested REGEXREPLACE examples.

Source: https://spreadsheetpractice.com/tools/formula-generator/regexreplace · Updated October 29, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on November 20, 2026

REGEXREPLACE replaces the parts of a text that match a regular expression.

Describe the task at [REGEXREPLACE formula generator](https://spreadsheetpractice.com/tools/formula-generator/regexreplace) and get a REGEXREPLACE formula for Excel and Google Sheets, tested on real data.

## Tested REGEXREPLACE examples

### Remove non-numeric characters

`=REGEXREPLACE(A2,"\D","")`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-non-numeric-characters)

### Swap first and last names

`=REGEXREPLACE(A2,"^(.+), (.+)$","$2 $1")`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/swap-first-and-last-names)

### Format messy phone numbers

`=REGEXREPLACE(REGEXREPLACE(A2,"\D",""),"^1?(\d{3})(\d{3})(\d{4})$","($1) $2-$3")`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/format-messy-phone-numbers-in-google-sheets)

### Remove special characters from text

`=TRIM(REGEXREPLACE(A2,"[^A-Za-z0-9 ]",""))`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-special-characters)

### Extract a number from text

`=VALUE(REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*"))`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/extract-a-number-from-text-in-google-sheets)

### Remove HTML tags from text

`=TRIM(SUBSTITUTE(REGEXREPLACE(A2,"<[^>]+>"," "),"&amp;","&"))`

Google Sheets. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-html-tags-in-google-sheets)

### Remove leading zeros from text

`=MID(A2,MATCH(TRUE,MID(A2,SEQUENCE(LEN(A2)),1)<>"0",0),LEN(A2))`

Excel. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-leading-zeros-from-text)

### Remove the last word from a cell

`=TEXTBEFORE(A2," ",-1)`

Excel. Result on the sample sheet: 5 rows (B2:B6). [See it and try it](https://spreadsheetpractice.com/formulas/remove-the-last-word)

## Questions

### What does the REGEXREPLACE formula generator do?

You describe the task in plain English, and it writes the formula, using REGEXREPLACE where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.

### What does REGEXREPLACE do?

REGEXREPLACE replaces the parts of a text that match a regular expression.

### Can I learn to write REGEXREPLACE formulas myself?

Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the REGEXREPLACE function page has a practice exercise.

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
