PostgreSQL regexp_substring

Postgresql regexp_substring

我有一个文本

Revision:3336179e1ebaa646cf281b7fb9ff36d1b23ce710$ modified $RevDate:10-04-2017 11:43:47$ by $Author:admin

你能帮我写 sql 查询,获取前 6 个修订字符 (333617) 和 RevDate 日期 (10-04-2017 11:43:47) 吗?提前致谢。

我试图获得修订

select (regexp_matches ('$Revision:3336179e1ebaa646cf281b7fb9ff36d1b23ce710$ modified $RevDate:10-04-2017 11:43:47$ by $Author:admin$', 
'^$Revision:(a-z0-9+)$'))[1] 

运气不好

我宁愿选择 substr 和 split_part(如果我没记错的话它们会更快):

t=# with v as (select 'Revision:3336179e1ebaa646cf281b7fb9ff36d1b23ce710$ modified $RevDate:10-04-2017 11:43:47$ by $Author:admin'::text l)
select substr(l,length('Revision:')+1,6),substr(split_part(l,'$',3),length('RevDate:')+1)
from v;
 substr |       substr
--------+---------------------
 333617 | 10-04-2017 11:43:47
(1 row)

如果首选正则表达式,固定表达式为:

select a[1] as revision, a[2] as date from (
  select regexp_matches('$Revision:3336179e1ebaa646cf281b7fb9ff36d1b23ce710$ modified $RevDate:10-04-2017 11:43:47$ by $Author:admin$',
 'Revision:([a-z0-9]{6}).*RevDate:([^$]+)') a ) atbl;