sql - POSTGRESQL 位置子串
问题描述
我有一个简单的问题(我认为)我无法解决:我有很多这样的标签:
'FOOT05_00120_RIG_1_GOAL_K'
但是所有记录的长度都不一样,我需要一个查询来获取最后一个之前的所有字符_
,有人吗我能怎么做?
(它可能在这样的查询中:
SELECT tag FROM Football
)
谢谢大家
解决方案
这个问题似乎几乎是为regexp_replace()
:
select regexp_replace(tag, '(.*)_[^_]*$', '\1')
from football;
正则表达式被解释为:
'(.*)_[^_]*$'
-^ remember this expression for a reference
--^ any character
---^ any number of times
----^ followed by _
-----^ followed by any characters that are not _
----------^ any number of times
-----------^ at the end of the string
推荐阅读
- sql - 使用 i/p 和 o/p 参数从链接服务器执行过程的 Openquery
- rust - 引用参数化函数的结构上的生命周期错误
- javascript - Phalcon PHP:使用 DataTable 在表中选择选项值 POST
- javascript - 无法为工具提示制作 css 三角形
- sql - 选择日期时间并按日期时间查询分组
- javascript - 未捕获的类型错误:在反应中使用自动完成时 items.filter 不是函数
- quantum-computing - 指向相关研究(论文)
- css - 从帖子文本 (CSS) 中删除白色 (Enter) 空格
- python - Q-Learning 政策与价值/政策迭代不一致
- javascript - 使用 AJAX 从另一个网站获取数据