REGEX Function – Tips & Tricks to Use it in Google Data Studio

Quite so often in Google Data studio, it it may be required to replace the  same character of data, which without regEx function would be very difficult and time consuming. This function can appear look deceptively very simple, but is in fact complex, requiring multiple conditions to work.  If you are new to this function, let me introduce it to you,  regex basically means  a language of characters and symbols that can be used to match patterns of text.

In Google Data Studio, you can use regex to make your filters and calculated fields more efficient and concise. The available regex functions also allow you to clean, organize, and transform your data in ways that otherwise wouldn’t be possible, in a fraction of the time.

Some of the common rules regarding regEx are as follows:

1. Case Sensitivity

In Data Studio, you must indicate whether your regular expressions should be treated as case sensitive or case insensitive. Case insensitive means that the case of a regex pattern is ignored. For example, analytics would match “analytics”, “Analytics”, “ANALYTICS”, or even “analytiCs”.

By default, a regex pattern is case sensitive. To force Data Studio to ignore the case of regex, insert (?i) at the beginning of the expression.

2. Escaping Special Characters

Most of the times, certain characters in Data studio,have special annotations (i.e. | $ ^ . + * ? ( ) [ ] { } /). If you ever want to use one of these characters literally—treating a comma as a comma, for example—then you need to “escape” the special character. This is usually done by adding a backslash  before the character you wish to escape.

In Data Studio, you need to double escape special characters with two backslashes. For example, matching “twitter.com” will require you to use twitter.com .

3. Matching Partial Strings

In most cases, Data Studio will attempt to match the full text of the field. This means that using the expression Search will not match a field containing “Organic Search” or “Paid Search”; You would need to use either (Organic|Paid) Search or .*Search.

In general, if you want to do a partial match, add .* before and after your regex. For example,  .*Customer.* will match “Customer” wherever it appears in the field.

The one exception is in filters, where Data Studio gives you the option to select “Regex Contains” as a match type.

Data Studio offers a REGEXP_MATCH function that can be used in calculated fields. This function returns true or false if your regex pattern matches the selected field. This is extremely useful for creating custom aggregations based on existing dimensions, including custom groupings of pages, geographic regions, or traffic sources.

For example: There is a data set in which multiple customer demographics are given, and there is a need to put a classification on the basis of the device category of the customers.

People who use mobile come in A category, those who use tablets come in B and laptops come in C.

Therefore, the Regexp Match code in the calculated field would be,

CASE

WHEN REGEXP_MATCH( Device, “Mobiles”) THEN “CATEGORY A”

WHEN REGEXP_MATCH (Device, “Tablets”) THEN “CATEGORY B”

WHEN REGEXP_MATCH( Device, “Laptops”) THEN “CATEGORY C”

ELSE “OTHER”

END

There are many more forms of Regex, as it is a very versatile function and serves a variety of purposes. However, these are the basic functions that have been covered.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top