使用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.';
我的尝试:
v_desc := regexp_replace(v_desc,'This product*{2,}','') ;
v_desc := regexp_replace(v_desc,'This product*{2,}*','') ;
期望的结果
v_desc := 'This product is used. Product may make you wealthy.';
答案 0 :(得分:3)
试试这个:
v_desc := regexp_replace(v_desc,'[^^](This product).*[.]', '') ;
以下是细分:
[^^] = Not the beginning of the line
(This product).*[.] = Searching for all instances of "This product" followed by a "."
这将最终搜索不在该行开头的“此产品...”的所有实例。
*评论后编辑
然后你想要的是(?<=)
背后的正面看法。它应该是这样的:
v_desc := regexp_replace(v_desc,'(?<=(This product).*)(This product).*[.]', '') ;
故障:
(?<=(This product).*) = Positive lookbehind.
(This product).*[.] = What is being searched for
如果表达式“This product ...”在它之前,它将仅触发下一个值为true。这将防止首次出现的“此产品”出现在要替换的值中。
我想指出,所有植入Regex都不支持前瞻和后视。我不知道PL / SQL的细节,所以我不能保证这会起作用。当我在Regex Hero上进行测试时,它确实有用。