SUBSTITUTE vs REGEXREPLACE

SUBSTITUTE swaps an exact text for another; REGEXREPLACE swaps anything that fits a pattern.

SUBSTITUTEREGEXREPLACE
Available inEvery versionExcel 365
What it findsAn exact textA pattern: digits, letters, spaces…
Remove everything but digitsSeveral nested SUBSTITUTEsOne formula: "\D" with ""
CaseCase-sensitiveCase-sensitive unless you pass 1

Syntax and example

SUBSTITUTE

=SUBSTITUTE(text, old_text, new_text, [instance_num])

=SUBSTITUTE(A2,"-","")

Replaces text with other text inside a cell, every time it appears.

REGEXREPLACE

=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])

=REGEXREPLACE(E2,"\D","")

Replaces whatever matches a pattern: remove everything that is not a digit, change formats, clean codes.

Which one to use?

To change one specific word or symbol, SUBSTITUTE. To clean varied formats (phones, codes), REGEXREPLACE.

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.

Advertising
Loading ad...

Ads help us keep WebHerramientas free for everyone

Practice it

Solve the exercise on the sheet; it is checked instantly. See all lessons · Formula translator

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.

Step 1/3

In B2, check whether each code has exactly 3 capital letters, a hyphen and 4 digits.

B2
ABCDEFG
1CodeValid?MessageNumberPhoneDigits only
2MEX-2041Order 4521 shipped55-1234-5678
3mx-2018Invoice 778 pending(33) 9876 5432
4GDL-9932Ticket 30215 open81 2233 4455
5QRO-12345Customer 66 called+52 222 111 0099
6MTY-7781Shipment 1290 delayed442.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 the difference between SUBSTITUTE and REGEXREPLACE?
SUBSTITUTE swaps an exact text for another; REGEXREPLACE swaps anything that fits a pattern.
When should I use SUBSTITUTE or REGEXREPLACE?
To change one specific word or symbol, SUBSTITUTE. To clean varied formats (phones, codes), REGEXREPLACE.