[]
        
(Showing Draft Content)

REGEXREPLACE

The REGEXREPLACE function replaces text in a string based on a specified regular expression pattern.

Syntax

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

Arguments

Argument

Description

text

[Required] The input text or cell reference containing text to replace.

pattern

[Required] Regular expression pattern to match.

replacement

[Required] Text to substitute for matched patterns.

occurrence

[Optional] Specifies which match to replace:

0 – Replace all (default)

Positive N – Replace Nth occurrence

Negative N – Replace Nth occurrence from end

case_sensitivity

[Optional] Case handling:

0 – Case-sensitive (default)

1 – Case-insensitive

Remarks

Returns: The modified string after replacements.

Examples

REGEXREPLACE("0000abcd","0","1", 2) gives the result 0100abcd

REGEXREPLACE("0000abcd","0","1", 0) gives the result 1111abcd

REGEXREPLACE("0000abcd","0","1", -1) gives the result 0001abcd

REGEXREPLACE("aaaAbcd","a","0", ,0) gives the result 000Abcd

REGEXREPLACE("aaaAbcd","a","0", ,1) gives the result 0000bcd

REGEXREPLACE("Sonia (378) 555-4195 Brown(878) 555-8622", "[0-9]+-", "***-") gives the result Sonia (378) ***-4195 Brown(878) ***-8622

REGEXREPLACE("JamesHenry","([A-Z][a-z]+)([A-Z][a-z]+)","$2, $1") gives the result Henry, James

Version Available

This function is available in product version 19.0 or later.