Looker Data Studio REGEX_CONTAINS在字符串中查找特定字符

huangapple go评论40阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月10日 22:47:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219823.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定