REGEXP_REPLACE

The REGEXP_REPLACE function replaces text using Google RE2 regular expressions.

In this article:

Sample Usage

REGEXP_REPLACE(Campaign , 'A_REALLY_LONG_NAME', 'ShortName')

Syntax

REGEXP_REPLACE(field_expression, regexp, replacement)

 

Parameters:

  • field_expression - an field or expression that includes a field
  • regexp - 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.

Examples

Replace a campaign code with a more readable name:

REGEXP_REPLACE(LOWER(Campaign), ".bc123", "Summer Sale")

This will replace codes like "abc123," "ABC123," "BBC123," etc. with "Summer Sale."

Was this helpful?
How can we improve it?