天天看点

oracle正则表达式函数之REGEXP_REPLACE和REGEXP_SUBSTR

具体来讲:

regexp_replace的意义是找到于给定模式匹配的字符串并用其他的字符串来替代。

其原型是:regexp_replace(x,pattern[,replace_string[,start[,occurence[match_option]]]])

每个参数的意思分别是:

x 待匹配的函数

pattern 正则表达式元字符构成的匹配模式

replace_string 替换字符串

start 开始位置

occurence 匹配次数

举例来讲:

select regexp_replace(’hello everybody,may I have your attention please?’,'b[[:alpha:]]{3}’,'one’) from dual将会返回结果:

hello everyone,may I have your attention please?

而regexp_substr函数的意义找出与给定模式匹配的字符串并返回,

其原型是:regexp_substr(x,pattern[,start[,occurence[match_option]]])

这里各参数的意义与前面的函数regexp_replace的含义是一样做的。

regexp_substr的例子如下:

select regexp_substr(’I love oracle very much’,'o[[:alpha:]]{5}’) from dual;

这里将会匹配出结果:

oracle来。这也是这个函数的返回结果。