英文:
Looker Data Studio REGEX_CONTAINS to Find a Specific Character Within a String
问题
我正在尝试在一个新字段中使用REGEX_CONTAINS来查找一个值是否包含句点。如果包含句点,它将被标记为一种方式,如果不包含,将被标记为另一种方式。
我编写了下面的语句,但它返回的标记好像每个都包含句点,即使它们实际上没有。
CASE WHEN last_touch_utm_medium = "email" AND REGEXP_CONTAINS(last_touch_utm_campaign, r'.') THEN "marketing" ELSE "flow" END
英文:
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
答案1
得分: 0
作为免责声明,类似于您的问题之前已经被问过,尽管我找不到确切的重复。问题在于.
是一个正则表达式的_元字符_,这意味着当它出现在正则表达式中时具有特殊含义。作为元字符,.
表示任意单个字符。要匹配字面上的句点,您应该用反斜杠对句点进行转义:
CASE WHEN last_touch_utm_medium = "email" AND
REGEXP_CONTAINS(last_touch_utm_campaign, r'\.')
THEN "marketing" ELSE "flow" END
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论