ID EN
#Dynamic array

REGEXREPLACE

Excel Functions

Replace text with a regex pattern

Syntax

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

Arguments

Parameter Description
text The text value to process.
pattern The pattern to replace.
replacement The text to replace with.
occurrence [optional] The instance to replace. Default = 0 = all instances.
case_sensitivity [optional] 0 = Case sensitive, 1= Case-insensitive. Default is 0.

Return Value

Text after all replacements

Details

The REGEXREPLACE function replaces text matching a specific regex pattern in a given text string. You can think of REGEXREPLACE as a much more powerful version of the simplistic SUBSTITUTE function. While both functions can be used to search and replace simple text strings, REGEXREPLACE can use regex, a powerful language built for matching and manipulating text values. This function is a major upgrade to Excel's rather primitive text functions. To use REGEXREPLACE, provide a text string, a regex pattern, and the replacement text. For example, to replace "t" with "b" in the text string "tuttle", you can use a formula like this: The formula replaces all three instances of "t" with "b". Note that REGEXREPLACE is case-sensitive by default. If we capitalize the first "t", only the second and th

Examples

Example - Basic usage

To use REGEXREPLACE, provide a text string, a regex pattern, and the replacement text. For example, to replace "t" with "b" in the text string "tuttle

EXCEL
=REGEXREPLACE("tuttle","t","b") // returns "bubble"
Example - Basic usage

The formula replaces all three instances of "t" with "b". Note that REGEXREPLACE is case-sensitive by default. If we capitalize the first "t", only th

EXCEL
=REGEXREPLACE("Tuttle","t","b") // returns "Tubble"
Example - Basic usage

To disable case sensitivity, provide a 1 for the case-sensitive argument:

EXCEL
=REGEXREPLACE("Tuttle","t","b",,1) // returns "bubble"
Example - Basic usage

With case sensitivity disabled, all three "t"s are replaced with "b". Another way to replace both "T" and "t" with "b" is to include both in a regex c

EXCEL
=REGEXREPLACE("Tuttle","[Tt]","b") // returns "bubble"
Example - Strip non-numeric characters

The REGEXREPLACE function provides an easy way to remove non-numeric characters from a text string. You can see an example below, where REGEXREPLACE i

EXCEL
=REGEXREPLACE(B5,"[^0-9]","")
Example - capitalize first letter in text string

REGEXREPLACE can perform certain transformations, for example making text upper or lower case. You can see an example of how this works in the workshe

EXCEL
=REGEXREPLACE(B5,"^(.)","\U$1")

See Also

REGEXTEST REGEXEXTRACT SUBSTITUTE