Excel REGEXREPLACE function
Replaces whatever matches a pattern: remove everything that is not a digit, change formats, clean codes. In Spanish Excel it is called REGEXREEMPLAZAR.
Syntax
English Excel
=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])
Spanish Excel (Mexico)
=REGEXREEMPLAZAR(texto, patrón, reemplazo, [aparición], [distinción_de_mayúsculas])
Spanish Excel (Spain, Latin America)
=REGEXREEMPLAZAR(texto; patrón; reemplazo; [aparición]; [distinción_de_mayúsculas])
| Argument | What it is |
|---|---|
| text | The text to change. |
| pattern | The regular expression to find. |
| replacement | The new text; $1 inserts the first group. |
| occurrenceoptional | 0 replaces all; 2 only the second; -1 the last. |
| case_sensitivityoptional | 0 is case-sensitive, 1 is not. |
Example
A regular expression describes a text pattern: \d is a digit, \D anything that is not, [A-Z] a capital letter, {4} repeats 4 times, + one or more, ^ and $ mark start and end. REGEXTEST says whether the text fits the pattern, REGEXEXTRACT pulls out the matching part and REGEXREPLACE replaces it.
=REGEXREPLACE(E2,"\D","")
Common mistake
Excel 365 only. "\D" with "" as the replacement leaves only a phone number’s digits, however it was typed.
About Ads
This site uses Google AdSense to display ads. These ads help us keep WebHerramientas completely free. Ads are managed by Google and meet strict security and privacy standards.
Ads help us keep WebHerramientas free for everyone
Practice REGEXREPLACE
Type the formula in the sheet and check it instantly. Spanish or English function names both work. See all lessons
Regular expressions: REGEXTEST, REGEXEXTRACT and REGEXREPLACE
A regular expression describes a text pattern: \d is a digit, \D anything that is not, [A-Z] a capital letter, {4} repeats 4 times, + one or more, ^ and $ mark start and end. REGEXTEST says whether the text fits the pattern, REGEXEXTRACT pulls out the matching part and REGEXREPLACE replaces it.
=REGEXTEST(A2,"^[A-Z]{3}-\d{4}$")REGEXPRUEBA = REGEXTESTREGEXEXTRACCION = REGEXEXTRACTREGEXREEMPLAZAR = REGEXREPLACEIn B2, check whether each code has exactly 3 capital letters, a hyphen and 4 digits.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Code | Valid? | Message | Number | Phone | Digits only | |
| 2 | MEX-2041 | Order 4521 shipped | 55-1234-5678 | ||||
| 3 | mx-2018 | Invoice 778 pending | (33) 9876 5432 | ||||
| 4 | GDL-9932 | Ticket 30215 open | 81 2233 4455 | ||||
| 5 | QRO-12345 | Customer 66 called | +52 222 111 0099 | ||||
| 6 | MTY-7781 | Shipment 1290 delayed | 442.555.7788 | ||||
| 7 |
Tip: while typing, click a cell or drag across several to insert their reference. F4 anchors the reference with $.
Frequently asked questions
- What is REGEXREPLACE called in Spanish?
- In Spanish Excel it is REGEXREEMPLAZAR. The formula =REGEXREPLACE(E2,"\D","") is written =REGEXREEMPLAZAR(E2;"\D";"") (or with commas in Mexico).
- Why does REGEXREPLACE use semicolons in some Excel versions?
- It depends on regional settings. Where the comma is the decimal mark (Spain, much of South America), Excel separates arguments with semicolons. English Excel and Mexican Spanish Excel use commas.
- What is the most common REGEXREPLACE mistake?
- Excel 365 only. "\D" with "" as the replacement leaves only a phone number’s digits, however it was typed.