正则表达式在指定字符串(不包括在内)前的匹配字符

问题描述 投票:0回答:3

REGEXP_SUBSTR(label),'。* _ dis')

这是用于SQL;

我的数据库是mysql

select REGEXP_SUBSTR(label) ,'.*_dis') as dis ,
substr(label,length(label))-1) as num
from table

table.lable col的数据:

1. a_b_dis_12
2. a_dis_13
3. c_d_dis_23
3. c_dis_22

我想获取'_ dis'之前的字符数字部分使用正则表达式

1.a_b   12
2.a     13
3.c_d   23
4.c     22

非常感谢!

sql regex oracle plsql
3个回答
1
投票

您可以如下使用regexp_substr

Select regexp_substr(your_column, '^(.*)_dis_[0-9]+$',1,1,null,1) as dis,
       Regexp_substr(your_column, '[0-9]+$') as num
  From your table

0
投票

您可以使用regexp_replace()


0
投票

我将如下使用regexp_replace()

© www.soinside.com 2019 - 2024. All rights reserved.