zun*_*arz 3 regex plsql oracle11g
使用 PL/SQL,如何删除除第一次出现以单词 开头的句子之外的句子This product?假设每个句子都以句点 ( .) 结尾,并且每个句子都以大写字母开头;例如:
v_desc varchar2(500);
v_desc := 'This product is used. Product may make you wealthy. This product may appear red. This product is not new.';
Run Code Online (Sandbox Code Playgroud)
我的尝试:
v_desc := regexp_replace(v_desc,'This product*{2,}','') ;
v_desc := regexp_replace(v_desc,'This product*{2,}*','') ;
Run Code Online (Sandbox Code Playgroud)
期望的结果
v_desc := 'This product is used. Product may make you wealthy.';
Run Code Online (Sandbox Code Playgroud)
尝试这个:
v_desc := regexp_replace(v_desc,'[^^](This product).*[.]', '') ;
Run Code Online (Sandbox Code Playgroud)
详细情况如下:
[^^] = Not the beginning of the line
(This product).*[.] = Searching for all instances of "This product" followed by a "."
Run Code Online (Sandbox Code Playgroud)
这最终将搜索不在行开头的“此产品...”的所有实例。
*评论后编辑
那么你想要的是背后积极的一面(?<=)。它应该看起来像这样:
v_desc := regexp_replace(v_desc,'(?<=(This product).*)(This product).*[.]', '') ;
Run Code Online (Sandbox Code Playgroud)
分解:
(?<=(This product).*) = Positive lookbehind.
(This product).*[.] = What is being searched for
Run Code Online (Sandbox Code Playgroud)
仅当表达式“此产品...”位于其前面时,它才会将下一个值触发为 true。这将防止“此产品”第一次出现在要替换的值中。
我想指出的是,并非所有正则表达式的植入都支持向前查找和向后查找。我不知道 PL/SQL 的细节,所以我不能保证这会起作用。当我在Regex Hero上测试时它确实有效。