The REGEXP_REPLACE function replaces text using Google RE2 regular expressions.
Sample usage
REGEXP_REPLACE(Campaign , '(Sale):(Summer)', '\\2 \\1')
Syntax
REGEXP_REPLACE(X, regular_expression, replacement)
Parameters
X
- a field or expression that includes a field.regular_expression
- a regular expression that matches a portion offield_expression.
replacement
- the text with which to replace the matched portion offield_expression.
Returns
The REGEXP_REPLACE function returns text
values.
Notes
Use double backslashed-escaped digits (\\1 to \\9) within the replacement argument to insert text matching the corresponding parenthesized group in the regex pattern. Use \\0 to refer to the entire matching text.
Examples
Example formula | Input | Output |
REGEXP_REPLACE(LOWER(Campaign), ".bc123", "Summer Sale") |
abc123 ABC123 BBC123 |
Summer Sale |
REGEXP_REPLACE(Campaign , '(.*):(.*)', '\\2 \\1') |
Sale:Summer Sale:Winter |
Summer Sale Winter Sale |