REGEXP_REPLACE

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 of field_expression.
  • replacement- the text with which to replace the matched portion of field_expression.

Notes

  • REGEXP_REPLACE uses RE2-style regular expressions.
  • The REGEXP_REPLACE function returns text values.
  • You can 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

Was this helpful?
How can we improve it?