(with Oracle11g
) 下面是如何替换第一个匹配项:
使用REGEXP_instr
并REGEXP_substr
能够应用于lower
匹配的模式
SELECT substr(it, 1 , REGEXP_instr( it, '(\(\D\))')-1)
||lower( REGEXP_substr(it, '(\(\D\))') )
||substr(it, REGEXP_instr( it, '(\(\D\))')+3, length(it))
FROM (SELECT 'i want what what is between <> in lower case : I am a test(E) (A) (HELLO)' it from dual) ;
如果你想要<>
它周围的怪异:
SELECT substr(it, 1 , REGEXP_instr( it, '(\(\D\))')-1)
|| '<'
||lower( REGEXP_substr(it, '(\(\D\))') )
|| '>'
||substr(it, REGEXP_instr( it, '(\(\D\))')+3, length(it))
FROM (SELECT 'i want what what is between <> in lower case : I am a test(E) (A) (HELLO)' it from dual) ;
我认为您不能在 Oracle 中使用递归正则表达式。因此,如果您希望能够替换 2 次出现:
SELECT substr(rit, 1 , REGEXP_instr( rit, '(\([[:upper:]]{1}\))')-1)
||lower( REGEXP_substr(rit, '(\([[:upper:]]{1}\))') )
||substr(rit, REGEXP_instr( rit, '(\([[:upper:]]{1}\))')+3, length(rit))
from (
(SELECT substr(it, 1 , REGEXP_instr( it, '(\([[:upper:]]{1}\))')-1)
||lower( REGEXP_substr(it, '(\([[:upper:]]{1}\))') )
||substr(it, REGEXP_instr( it, '(\([[:upper:]]{1}\))')+3, length(it)) rit
FROM (SELECT 'i want what what is between <> in lower case : I am a test(E) (A) (HELLO)' it from dual))
) ;
(+我用\D
哪个[[:upper:]]{1}
更准确替换)