Snowflake cloud data platform 如何在snowflake中仅返回单个正则表达式匹配组?

Snowflake cloud data platform 如何在snowflake中仅返回单个正则表达式匹配组?,snowflake-cloud-data-platform,Snowflake Cloud Data Platform,我有一个正则表达式,它有多个匹配组 如何在snowflake中指定要返回的匹配组 我使用的是REGEXP\u SUBSTR,但如果它们工作得更好,我很乐意使用替代方法。中有一个名为occurance的参数,它允许您指定要返回的匹配项的哪个匹配项 例如: select regexp_substr('bird is the word','\\w+',1,1); -- returns "bird" select regexp_substr('bird is the word','\\w+',1,4);

我有一个正则表达式,它有多个匹配组

如何在snowflake中指定要返回的匹配组

我使用的是REGEXP\u SUBSTR,但如果它们工作得更好,我很乐意使用替代方法。

中有一个名为occurance的参数,它允许您指定要返回的匹配项的哪个匹配项

例如:

select regexp_substr('bird is the word','\\w+',1,1); -- returns "bird"
select regexp_substr('bird is the word','\\w+',1,4); -- returns "word"
中有一个名为occurance的参数,允许您指定要返回的匹配项的哪个匹配项

例如:

select regexp_substr('bird is the word','\\w+',1,1); -- returns "bird"
select regexp_substr('bird is the word','\\w+',1,4); -- returns "word"
TL;DR:不能完全做到这一点,但您可以使用“e”选项,并将非捕获组与?:re一起使用

所以,为了澄清这一点,尼尔似乎在要求一些东西来回报他的话

不幸的是,我认为Snowflake目前并不完全支持这种功能。REGEXP_SUBSTR有一个“e”extract参数,它只允许您提取一个组,但它总是提取第一个组。原因是,今天的引用参数意味着整个regexp出现在字符串中。范例

你可以通过在你想要的之前不使用分组来实现你想要的,例如

select regexp_substr('bird is the word','bird (is) (the) (word)',1,1,'e');
-> is
select regexp_substr('bird is the word','bird is the (word)',1,1,'e');
-> word
但是,如果您想使用分组来表示备选方案,例如

select regexp_substr('cow is the word','(bird|cow) is the (word)',1,1,'e');
-> cow
尽管如此,我认为提供一个选项来提取一个特定的组号还是有价值的,它将随着Snowflake的开发而提高:

TL;DR:不能完全做到这一点,但您可以使用“e”选项,并将非捕获组与?:re一起使用

所以,为了澄清这一点,尼尔似乎在要求一些东西来回报他的话

不幸的是,我认为Snowflake目前并不完全支持这种功能。REGEXP_SUBSTR有一个“e”extract参数,它只允许您提取一个组,但它总是提取第一个组。原因是,今天的引用参数意味着整个regexp出现在字符串中。范例

你可以通过在你想要的之前不使用分组来实现你想要的,例如

select regexp_substr('bird is the word','bird (is) (the) (word)',1,1,'e');
-> is
select regexp_substr('bird is the word','bird is the (word)',1,1,'e');
-> word
但是,如果您想使用分组来表示备选方案,例如

select regexp_substr('cow is the word','(bird|cow) is the (word)',1,1,'e');
-> cow

尽管如此,我认为提供一个选项来提取一个特定的组号还是有价值的,它将随着雪花开发而提高:

似乎对匹配组不起作用,我只是得到null:select regexp_substr‘bird是单词’,‘bird是单词’,1,4doe似乎对匹配组不起作用,我刚刚得到空值:选择regexp_substr'bird is the word','bird is the word',1,4snowflake不支持非捕获组。如果它真的这么做了,那就太好了。雪花不支持非捕获组。如果真的有,那就太好了。