我从oracle文档中看到,我可以做一个| b,它将匹配字符'a'或字符'b'的所有实例。我想知道regexp中是否有可能有'a'而不是'b',例如匹配'a'的所有实例,除非a后跟'b'。
所以这3个字符串
我希望匹配1和2而不是3。
答案 0 :(得分:1)
你可以尝试:
with x as (
select 'AAAA' as str from dual
union all
select 'ACAD' as str from dual
union all
select 'AAAB' as str from dual
)
select * from x
where regexp_like(str, '[aA][^bB]')
and NOT regexp_like(str, '[aA][bB]')
输出:
AAAA
ACAD
注意:如果你不在乎A是否跟着其他一些非B字符,你可以这样做:
with x as (
select 'AAAA' as str from dual
union all
select 'ACAD' as str from dual
union all
select 'AAAB' as str from dual
)
select * from x
where regexp_like(str, '[aA]')
and NOT regexp_like(str, '[aA][bB]')
匹配“AAAA”或“XYZA”