[英]AWS Athens regexp_extract
I am trying to extract a part of the string 'c://abcd /abcdef/0012wetr_1234567890.csv' between the last '/' and '_' characters.我正在尝试提取最后一个“/”和“_”字符之间的字符串“c://abcd/abcdef/0012wetr_1234567890.csv”的一部分。
0012wetr
0012wetr
I am able to extract everything after the last '/' character我能够提取最后一个“/”字符后的所有内容
select regexp_extract('c://abcd /abcdef/0012wetr_1234567890.csv', '([^/]*)$');
0012wetr_1234567890.csv
0012wetr_1234567890.csv
Unfortunately I am stuck and don't know how to split it further.不幸的是,我被卡住了,不知道如何进一步拆分它。
Your help would be appreciated.您的帮助将不胜感激。 Cheers, A.
干杯,A.
Maybe it is overkill but I managed to get required result using next combination of lookaheads - (??\/)[^\/]+(?=_)
:也许这是矫枉过正,但我设法使用前瞻的下一个组合获得了所需的结果 -
(??\/)[^\/]+(?=_)
:
select regexp_extract('c://abcd /abcdef/0012wetr_1234567890.csv', '(?!\/)[^\/]+(?=_)');
Output: Output:
_col0 ![]() |
---|
0012wetr ![]() |
You can use a REGEXP_REPLACE
approach:您可以使用
REGEXP_REPLACE
方法:
REGEXP_REPLACE('c://abcd /abcdef/0012wetr_1234567890.csv', '.*/([^_]+).*', '$1')
See the regex demo .请参阅正则表达式演示。
If you need to keep the result blank if there is no match, add |.+
at the end of the pattern:如果在没有匹配项的情况下需要将结果保留为空白,请在模式末尾添加
|.+
:
REGEXP_REPLACE('c://abcd /abcdef/0012wetr_1234567890.csv', '.*/([^_]+).*|.+', '$1')
Details :详情:
.*
- any zero or more chars other than line break chars as many as possible .*
- 尽可能多的除换行符以外的任何零个或多个字符/
- a /
char /
- 一个/
字符([^_]+)
- Group 1: any one or more chars other than _
([^_]+)
- 第 1 组:除_
以外的任何一个或多个字符.*
- the rest of the line .*
- 该行的 rest|
- or .+
- any one or more chars other than line break chars as many as possible. .+
- 除换行符以外的任何一个或多个字符,尽可能多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.