Skip to main content

REPLACEREGEX

The REPLACEREGEX function is used to replace one string with another using regular expressions.

It has two variations of the syntax. The first one takes three arguments: the original string to look in, the regular expression to use, and the new string to replace with. The second one has an additional argument, which is a boolean value indicating whether the case of the item should be ignored.

Syntax

string REPLACEREGEX(string value, string expression, string newValue)
string REPLACEREGEX(string value, string expression, string newValue, bool ignoreCase)

Input

ObjectData TypeDescription
valueStringThe original string to look in.
expressionStringThe regular expression to use.
newValueStringThe new string to put in place.
ignoreCaseBooleanA boolean indicating that the case of the item should be ignored.

Example

An example use case for this function is when you need to replace certain characters in a filename that are not valid for filenames in SharePoint. These characters include ~ " # % & * : < > ? / \ { | }.

You can use the REPLACEREGEX function to replace any of these characters with an underscore using the following expression:

REPLACEREGEX(FileName, "[~\"#%&*:<>?/\\{|}]", "_")

This would replace any of these characters in the filename with an underscore.