数组输出的正则表达式

regex for an array output

您好,我的一个画面行中有一个箭头输出。我如何通过正则表达式将其缩短为另一个计算字段。

示例 1 行有 2 个项目:

[{self=https://blah.blahblah.com/rest/api/2/component/1111, id=1111, name=abc, description=123}, {self=https://blah.blahblah.com/rest/api/2/component/123456, id=123456, name=wow, description=so cool}]

需要输出:

name=abc and description=123, name=wow and description=so cool

我会在 tableau

中使用 REGEXP_EXTRACT

编辑:我也可以在进入画面之前通过 sql 在 redshift/athena 中尝试这样做。

可以使用 tableau 计算字段和正则表达式实现所需的输出,但它太脆弱,如果您的数据具有比您的示例更多的 flexible/nested 结构,则它的可扩展性不强。

REGEXP_EXTRACT([C1],'((name)=[aA-zZ0-9 ]+)') 
+ ' and '
+ REGEXP_EXTRACT([C1],'((description)=[aA-zZ0-9 ]+)')
+ ' , ' 
+ REGEXP_EXTRACT_NTH([C1],'(\,\W+\{)([aA-zZ0-9 \n\/"=:.,]+)(name=[aA-zZ0-9 ]+)',3)
+ ' and ' 
+ REGEXP_EXTRACT_NTH([C1],'(\,\W+\{)([aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 ]+)',3)

您的数据来源是什么?如果您可以打包到有效的 JSON 中,您可以使用 Redshift JSON_EXTRACT_ARRAY_ELEMENT_TEXTJSON_EXTRACT_PATH_TEXT 函数在用数据输入画面之前准备数据。


更新

在正则表达式中有足够的 IFs 和重复你几乎可以实现任何事情但代价是什么

REGEXP_EXTRACT([C1],'((name)=[aA-zZ0-9 \-]+)') 
+ ' and '
+ REGEXP_EXTRACT([C1],'((description)=[aA-zZ0-9 \-]+)') 

+ 
IF ISNULL(REGEXP_EXTRACT_NTH([C1],'(\,\W+\{)([aA-zZ0-9 \n\/"=:.,]+)(name=[aA-zZ0-9 \-]+)',3))
THEN ''
ELSE ' , ' 
    + REGEXP_EXTRACT_NTH([C1],'(\,\W+\{)([aA-zZ0-9 \n\/"=:.,]+)(name=[aA-zZ0-9 \-]+)',3)
    + ' and ' 
    + REGEXP_EXTRACT_NTH([C1],'(\,\W+\{)([aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)',3)
END 

+
IF ISNULL(REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)', 2))
THEN ''
ELSE ', ' + REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(name=[aA-zZ0-9 \-]+)', 2) 
    + ' and ' + REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)', 2)
END 

+
IF ISNULL(REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(\W+\{[aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)', 3))
THEN ''
ELSE ', ' + REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(\W+\{[aA-zZ0-9 \n\/"=:.,]+)(name=[aA-zZ0-9 \-]+)', 3)
    + ' and ' + REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(\W+\{[aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)', 3)
END

+
IF ISNULL(REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)', 3))
THEN ''
ELSE ', ' + REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(name=[aA-zZ0-9 \-]+)', 3)
    + ' and ' + REGEXP_EXTRACT_NTH([C1], '(\,\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(\W+\{[aA-zZ0-9 \n\/"=:.,\}]+\,\W+\{[aA-zZ0-9 \n\/"=:.,]+)(description=[aA-zZ0-9 \-]+)', 3)
END