英文:
Snowflake Regex - extract string between delimiter
问题
需要帮助在Snowflake中使用正则表达式获取所需的输出。从'-'后的文本一直到';'。
输入字符串为'008-1994; 023-1905; 030-2330'
期望结果是1994;1905;2330
示例2:
输入字符串为'008-XXX; 023-YYY; 030-ZZZ ; 042-AAA'
期望结果是XXX; YYY; ZZZ; AAA
提前感谢。
英文:
Need help in getting desired output in snowflake using RegEx. Text after'-' and up to ';'
Input string '008-1994; 023-1905; 030-2330'
Desired result 1994;1905;2330
Ex2
Input string '008-XXX; 023-YYY; 030-ZZZ ; 042-AAA'
Desired result XXX; YYY; ZZZ; AAA
Thanks in advance.
答案1
得分: 1
这是使用SPLIT
的版本
--input string
set str = '008-1994; 023-1905; 030-2330';
select listagg(split_part(C.value::string, '-', 2)) from LATERAL FLATTEN(input=>split($str, ' ')) as c;
输出:
英文:
This is the version using a SPLIT
--input string
set str = '008-1994; 023-1905; 030-2330';
select listagg(split_part(C.value::string, '-', 2)) from LATERAL FLATTEN(input=>split($str, ' ')) as c;
Output:
答案2
得分: 0
SET STR = '008-1994; 023-1905; 030-2330';
SELECT
REGEXP_SUBSTR($STR, '\d+-(\d+);\s', 1, 1, 'e', 1) AS FIRST,
REGEXP_SUBSTR($STR, '\d+-(\d+);\s', 1, 2, 'e', 1) AS SECOND,
REGEXP_SUBSTR($STR, '\d+-(\d+)', 1, 3, 'e', 1) AS THIRD;
英文:
SET STR= '008-1994; 023-1905; 030-2330';
SELECT
REGEXP_SUBSTR($STR,'\\d+-(\\d+);\\s',1,1,'e',1) AS FIRST
,REGEXP_SUBSTR($STR,'\\d+-(\\d+);\\s',1,2,'e',1) AS SECOND
,REGEXP_SUBSTR($STR,'\\d+-(\\d+)',1,3,'e',1) AS THIRD;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论