# REGEXREPLACE

## Content

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

## Syntax

REGEXREPLACE(text, pattern, replacement, [occurrence], [case\_sensitivity])

## Arguments

| @cols=1:**Argument** | @cols=1:**Description** |
| -------- | ----------- |
| @cols=1:@rows=1:*text* | @cols=1:@rows=1:[Required] The input text or cell reference containing text to replace. |
| @cols=1:@rows=1:*pattern* | @cols=1:@rows=1:[Required] Regular expression pattern to match. |
| @cols=1:@rows=1:*replacement* | @cols=1:@rows=1:[Required] Text to substitute for matched patterns. |
| @cols=1:@rows=1:*occurrence* | @cols=1:@rows=1:[Optional] Specifies which match to replace:<br>**0** – Replace all (default)<br>**Positive N** – Replace Nth occurrence<br>**Negative N** – Replace Nth occurrence from end |
| @cols=1:@rows=1:*case\_sensitivity* | @cols=1:@rows=1:[Optional] Case handling:<br>**0** – Case-sensitive (default)<br>**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.