Oracle 正则字符簇补充:
[[:digit:]] 任何数字[0-9] [[unct:]] 任何标点符号
---测试Oracle正则字符簇
--查询指定字符是否以d开头f结尾中间匹配任意字母0至10次
select 1 from dual where regexp_like('dshGapf','^d[[:alpha:]]{0,10}f$'); 结果:1
当前测试了这些
--[ ] elect 1 from dual where regexp_like('fsdf','[a-z]'); select 1 from dual where regexp_like('fsDdf','[A-Z]'); select 1 from dual where regexp_like('fsD7df','[0-9]'); select 1 from dual where regexp_like('fsD7df','[0-9a-aA-Z]'); --{ } select 1 from dual where regexp_like('fsDa7adf','a{2}');--匹配是否有两个连续a --^ $ select 1 from dual where regexp_like('fsD7aadf','^f'); select 1 from dual where regexp_like('fsD7aadf','f$'); --* + ? select 1 from dual where regexp_like('fsD7aadf','fH*'); select 1 from dual where regexp_like('fsD7aadf','f+'); select 1 from dual where regexp_like('fsD7aaadf','(a)?');
但是还有这个未搞懂
--1 select 1 from dual where regexp_like('fsD7aadf','([a])1'); select 1 from dual where regexp_like('SaagAfd','(a)1'); select 1 from dual where regexp_like('abQqqfdfdfddffqweyifasaf','([a-d])1'); select * from dual where regexp_like('abQqqfdfdfdddffqweyifasaf','(.)2'); select 1 from dual where regexp_like('abQqqfdfdfdddffqweyifasaf','(.)1{2}') select regexp_replace('09/29/2008', '^([0-9]{2})/([0-9]{2})/([0-9]{4})$', '3-1-2') replace from dual;
经典案例
--不包含任何字母 select 1 from dual where not regexp_like('24G3324','[[:alpha:]]'); 无返回结果
--把指定字符串中任何几个连续的#只保留一个
select REGEXP_REPLACE('12#666##799####','[.#.]{1,}', '#') from dual; 结果:12#666#799#
--查询指定字符串是否以a开头,并且不区分大小写,i代表不区分大小写
select 1 from dual where regexp_like('afdsf','^A','i'); 结果:1
测试案例
--查询指定字符串是否以d开头f结尾中间可以出现任意字符零至多次,.代表任意字符(除了 换行符),*代表匹配零个或多个 select 1 from dual where regexp_like('dsnf;ang11@vvhapf','^d.*f$'); 结果:1 --查找指定字符串是否以d开头f结尾中间匹配a-z字符0-10次 select 1 from dual where regexp_like('dshapf','^d[a-z]{0,10}f$'); 结果:1
--把指定字符串中包含s加任意两个字符加f的字符创替换成=
select 'dfs23fs',regexp_replace('dfs23fs','s..f','=') from dual; 结果:dfs23fs df=s
--截取指定字符串从第一个位置第一次出现不以逗号开头的第1至多个字符
select regexp_substr('12,43fd,er55','[^,]+',1,1,'i') from dual; 结果:12