Search code examples
looker-studio

Looker Data Studio REGEX_CONTAINS to Find a Specific Character Within a String


I am trying to use REGEX_CONTAINS in a new field to find if a value has a period in it or not. If it does, it will be tagged one way and if not it will be tagged the other way.

I wrote this statement below and it's returning the tagging as if everything has a period even when it does not

CASE WHEN last_touch_utm_medium = "email" AND REGEXP_CONTAINS(last_touch_utm_campaign,r'.') THEN "marketing" ELSE "flow" END


Solution

  • As a disclaimer, questions similar to yours have been asked before, though I could find no exact duplicate. The issue here is that . is a regex metacharacter, meaning that it has a special meaning when appearing in a regular expression. As a metacharacter, . means any single character. To match a literal dot, you should escape the dot with backslash:

    CASE WHEN last_touch_utm_medium = "email" AND
              REGEXP_CONTAINS(last_touch_utm_campaign, r'\.')
         THEN "marketing" ELSE "flow" END