如果它真的是“行首+可选空格+测试+空格”,如何只从大字符串中解释特定单词(例如test)。还允许单词'test'的混合大小写
答案 0 :(得分:0)
对所有参数使用REGEXP_REPLACE,你可以......
如果您要删除第二个测试实例,或TeSt或TEST,这将有效。你没有提供很多例子和预期结果。
-- Start test data
with test_data as
(select 'TeSt this is how I am going to tEst going for' as test_string from dual union all
select 'test hello everyone how are you test' from dual union all
select 'test_find1();' from dual union all
select 'test sample 1;' from dual union all
select 'TEST sample 2;' from dual union all
select 'test1 hope this is will help test2;' from dual)
-- End test data
select test_string,
CASE WHEN REGEXP_LIKE(test_string,'^test\s+','i') THEN
REGEXP_REPLACE(test_string,'test','', 1, 2, 'i')
ELSE NULL END AS result
from test_data;
有关REGEXP_REPLACE here
的更多信息答案 1 :(得分:0)
我正在使用您输入的字符串,如下所示
' TeSt this is how I am going to tEst going for '
并故意在开头和结尾保留一些空格。下面的代码生成您想要的输出。另外,正如您所提到的,它将替换TEST一词的所有实例而不考虑大小写。 我希望这会有所帮助。
Select
REGEXP_REPLACE( --Using RegExp_replace
ltrim(rtrim( --Trimming the white spaces
input1)), --using the input
'TEST', --search criteria
'', --Replace with string
2, --Starting with which character (you mentioned first occerance should remain
0, --Replace all subsequent occurances
'i') --case in-sensitive
from (
Select ' TeSt this is how I am going to tEst going for' as input1 from dual --this is your INPUT)
谢谢, 桑托什