如何提取最后一个和倒数第二个空格之间的所有字符?
例如,我有以下列:
col1 |
---|
A BCDE |
ABCE |
ABC |
我想得到以下内容:
col1 |
---|
D |
C |
B |
谢谢!
I have for example the following column:
col1 |
---|
A B C D E |
A B C E |
A B C |
I want to get the following:
col1 |
---|
D |
C |
B |
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以使用 regexp_extract:
与 mytable as (
选择 'ABCD E' col1 联合所有
选择“ABC E”并全部
选择“AB C”
)
select regexp_extract(col1, '\s+([^\s]+)\s+[^\s]*$',1) from mytable
结果:
Regex
'\\s+([^\\s]+ )\\s+[^\\s]*$'
表示:\\s+
- 空格 1+ 倍([^\\s]+)
- 要提取的组,而不是空格1+ 次\\s+
- 1+ 空格[^\\s]*
- 任何时候都不是空格在此处输入代码
$ - 结束字符串的You can use regexp_extract:
with mytable as (
select 'A B C D E' col1 union all
select 'A B C E' union all
select 'A B C'
)
select regexp_extract(col1, '\s+([^\s]+)\s+[^\s]*$',1) from mytable
Result:
Regex
'\\s+([^\\s]+)\\s+[^\\s]*$'
means:\\s+
- space 1+ times([^\\s]+)
- group to extract, not space 1+ times\\s+
- 1+ space[^\\s]*
- not a space any timesenter code here
$ - end of the string