Regex in Data Studio Calculated Fields: Patterns I Reuse

REGEXP_MATCH, REGEXP_CONTAINS and REGEXP_EXTRACT patterns I use in Data Studio calculated fields.

Regular expressions are one of the most useful tools in Data Studio (formerly Looker Studio) calculated fields, and also one of the easiest to get wrong. I’m Harsh Khubchandani, an independent Data Studio consultant in New Delhi, and these are the patterns I reach for most.

REGEXP_MATCH for grouping

REGEXP_MATCH checks whether the whole value matches a pattern, which makes it useful inside a CASE statement. I use it to group page paths into sections, such as everything under /blog/ or /services/.

REGEXP_CONTAINS for partial matches

When I only need to know whether a value contains a word anywhere, REGEXP_CONTAINS is simpler and avoids having to add wildcards at both ends of the pattern.

REGEXP_EXTRACT to pull out a piece

REGEXP_EXTRACT returns the part of a value that matches a capture group. I use it to take a product code out of a URL or a campaign name out of a longer tag.

Test before trusting

Before using a regex field in a client report, I put it in a table next to the original value and scan the results for misses. Case sensitivity and special characters like dots and question marks catch people out most often.

More practical Data Studio notes at datastudioconsultant.com.


Write a comment