Skip to main content



RegexReplace Function

Replaces all occurrences of a Regular Expression pattern with a string.

Syntax 1

RegexReplace(string, searchPattern, replaceValue)

Replaces all occurrences of a Regular Expression pattern with a string.

Arguments

string String - A string.

searchPattern String - A regular expression pattern to search for.

replaceValue String - A string to replace all matches of pattern.

Syntax 2

RegexReplace(string, searchPattern, replaceValue, caseSensitive)

Replaces all occurrences of a Regular Expression pattern with a string.

Arguments

string String - A string.

searchPattern String - A regular expression pattern to search for.

replaceValue String - A string to replace all matches of pattern.

caseSensitive Boolean - True to be case-sensitive in the regular expression pattern.

Remarks

  • The pattern may include a single group (), in which case the entire expression is matched while only the group is replaced.

Example:

RegexReplace("Words, with punctuation!", "[^a-z0-9]", ""); // returns "Words, with".

Example:

RegexReplace("words, with punctuation!", "[^a-z0-9]", "", true); //  returns "with".