oracle find to first hyphens after last vertical bar
-
24-02-2021 - |
题
oracle find to first hyphens after last vertical bar using REGEXP_REPLACE
SELECT REGEXP_REPLACE ('sadsa|dd|g - g|hh|yyyyy - tttt - ooo', '.*(\|)(?!.*\|).*?\-{1}', '' ) FROM dual;
string input
'sadsa|dd|g - g|hh|yyyyy - tttt - ooo'
expected output
'sadsa|dd|g - g|hh|yyyyy -'
this regex working on notepad++ but not on oracle
.*(\|)(?!.*\|).*?\-{1}
解决方案
create table t (
c varchar2(64)
);
insert into t values ('sadsa|dd|g - g|hh|yyyyy - tttt - ooo');
insert into t values ('sadsa|dd|g - g|hh|yyyyy - tttt | - ooo');
insert into t values ('sad -sa|dd|g - g|hh|yy yyy tttt ooo');
select regexp_replace(c,'(.*)\|([^|-]*)-[^|]*','\1|\2-') from t;
gives
sadsa|dd|g - g|hh|yyyyy -
sadsa|dd|g - g|hh|yyyyy - tttt | -
sad -sa|dd|g -|hh|yy yyy tttt ooo
see
不隶属于 dba.stackexchange