REGEXREPLACE

REGEXREPLACE finds appearances of a regex within a block of text and replaces it.

Function category: Text

Syntax

REGEXREPLACE(arg1, arg2, arg3)

Arguments

Description

arg1

String to be searched.

arg2

regex pattern to be searched in the string. Any match replaced with arg3.

arg3

String that replaces any instances of arg2 found.

Examples

Example 1: Search and replace a string

Let's say we're given a response with that following vehicle information:

{
"data":{
"mechanic_reports":{
"vehicle_1":{
"description":"The car was still functional, but had bad axels, and was in bad condition."
}
}
}
}

If we know that the description attribute is going to have a standard structure and used standardized terminology, we can do a search and replace using REGEXREPLACE. In this example, we search for "bad" and replace it with "imperfect":

REGEXREPLACE("The car was still functional, but had a bad axels, and was in bad condition.", "ba.", "imperfect")

This returns the following string:

"The car was still functional, but had imperfect axels, and was in imperfect condition."