1
string="[(ETLCoreB15,COB-W#2018-05-25, [ETLCoreB4,ETLCoreB15],[ETLCoreB1,ETLCoreB15]),(ETLCoreB20,COB-A#2018-05-25, [ETLCoreB8,ETLCoreB20],[ETLCoreB1,ETLCoreB20])]"

我希望输出作为最后一次etlcoreb1使用regex_extract

4

1 回答 1

0

用于split()字符串拆分regex_replacetranslate删除某些字符。我已经评论了我在代码中的每一步所做的事情。您的字符串已解析:

select    split(
           translate(
            split(
               split(
                 regexp_replace(str,'^\\[|\\]$',''), --remove outer []
              '\\)\\s*,')[1], --split by )<any spaces>comma and take second string, which is second struct
            '\\]\\s*,')[1], --split by ]<any spaces>comma  got [ETLCoreB1,ETLCoreB20])
             '([])',''), --remove ()[] characters
            ',')[0] --split by comma and take first element

from
(select '[(ETLCoreB15,COB-W#2018-05-25, [ETLCoreB4,ETLCoreB15],[ETLCoreB1,ETLCoreB15]),(ETLCoreB20,COB-A#2018-05-25, [ETLCoreB8,ETLCoreB20],[ETLCoreB1,ETLCoreB20])]' as str) s

结果:

OK
ETLCoreB1
Time taken: 1.414 seconds, Fetched: 1 row(s)

希望你已经抓住了这个想法。

于 2018-06-08T09:28:20.130 回答