【问题标题】:Postgresql Regexp_replace groupPostgresql Regexp_replace 组
【发布时间】:2015-08-15 11:51:02
【问题描述】:

对不起我的英语

我有这个问题

select regexp_replace('Hello OBLIG: 451451, world OBLIG: 12123456789, Task OBLIG: 789456123, world ', '(OBLIG: )([^,]*)', '\1\2' , 'g')

我需要返回这样的东西

Hello OBLIG: 1451, world OBLIG: 6789, Task OBLIG: 6123, world

“OBLIG:”后面的数字应该是最后4位

有什么想法吗?

【问题讨论】:

    标签: postgresql regexp-replace


    【解决方案1】:

    你快到了。

    select regexp_replace(
        'Hello OBLIG: 451451, world OBLIG: 12123456789, Task OBLIG: 789456123, world ', 
        '(OBLIG: )([[:digit:]]*)([[:digit:]]{4})', '\1\3' ,
        'g'
    );
    

    当然,这是假设您总是在每个数字中至少有 4 位数字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-19
      • 2020-12-26
      • 2017-11-07
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      相关资源
      最近更新 更多