在 Tableau 中使用 REGEXP_EXTRACT 提取字符串时获取 "null"

Getting "null" when extracting string using REGEXP_EXTRACT in Tableau

我一直在尝试在 Tableau 中使用 REGEXP_EXTRACT 函数但没有成功(见下图)。我有一个字符串列 'FOB',我想提取前导大写字母。有时大写字母后面有破折号,有时没有,所以我在创建的字段中使用了以下语法 'Advertiser':

REGEXP_EXTRACT([FOB],'^[A-Z]*')  

但是,这会产生一个充满 "null" 的列。奇怪的是,即使我将模式从 '^[A-Z]*' 更改为 'SDM',它仍然是一样的。 Tableau 似乎没有启用正则表达式...

我确实在线检查了我的正则表达式 here 并且它起作用了...真的很困惑,我们将不胜感激。

由于您需要提取每个 [FOB] 列单元格中的第一个字符,因此您需要使用 ^ 锚点和一个 [A-Z] 字符 class、但也你需要用捕获组(即成对的圆括号,(...))包裹模式来告诉Tableau 你需要提取这个模式部分:

REGEXP_EXTRACT([FOB],'^([A-Z])')
                       ^     ^

要提取所有(一个或多个)前导大写字母,请添加 +:

REGEXP_EXTRACT([FOB],'^([A-Z]+)')
                             ^

参见Mark Jackson's regex blog excerpt

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.