Getting “null” when extracting string using REGEXP_EXTRACT in Tableau
我一直在尝试在Tableau中使用REGEXP_EXTRACT函数而没有成功(请参见下图)。 我有一个字符串列'FOB',我想提取前导大写字母。 有时在大写字母后面有一个破折号,有时没有,所以我在创建的字段" Advertiser"中使用了以下语法:
1 | REGEXP_EXTRACT([FOB],'^[A-Z]*') |
但是,这将产生一个充满"空"的列。 奇怪的是,即使我将模式从'^ [A-Z] *'更改为'SDM',也还是一样。 似乎Tableau没有启用正则表达式...
我确实在这里在线检查了我的正则表达式,它确实有效...真的很困惑,我们将不胜感激。
由于您需要提取每个[FOB]列单元格中的第一个字符,因此需要使用
1 2 | REGEXP_EXTRACT([FOB],'^([A-Z])') ^ ^ |
要提取所有(一个或多个)前导大写字母,请添加
1 2 | REGEXP_EXTRACT([FOB],'^([A-Z]+)') ^ |
参见Mark Jackson的正则表达式博客摘录:
The whole pattern is wrapped in parenthesis to tell Tableau what part of the pattern to return. This is an update from the earlier beta version I was using when I created this post. The nice thing about this addition is that Tableau lets you pattern match on a larger portion of the string, but allows you to return a subset of the pattern.