REGEXP_EXTRACT

The REGEXP_EXTRACT function creates dimension values by extracting them from a source dimension using Google RE2 regular expressions.

See the REGEXP_MATCH article for general information on regular expressions in Data Studio.

Sample Usage

REGEXP_EXTRACT(Campaign , 'TYPE:(.*)')

Syntax

REGEXP_EXTRACT(X, regular_expression)

 

Parameters:

  • X - a field or expression that includes a field.
  • regular_expression - a regular expression that extracts a portion of field_expression.

Notes

  • Regular expressions in Data Studio use RE2-style syntax.
  • Escape special characters with 2 backslash characters:
    REGEXP_EXTRACT(MyField, "foo(\\.)bar") extracts the literal period character.
  • Regular expressions are case-sensitive by default. You can make the match case-insensitive using the (?i) flag:
    REGEXP_EXTRACT(field_expression, '(?i)(a.*)') extracts both "abc123" and "ABC123".
  • The REGEXP_EXTRACT function returns text values.

Example

Extract the top-level directory in a URL:

REGEXP_EXTRACT( URL , '^https://[^/]+/([^/]+)/' )

For example, if the URL field contained this page's address, the function above would return datastudio.

Was this helpful?
How can we improve it?