Using PL/SQL, how can I remove sentences, except the first occurrence of a sentence that begin with the words This product? Assume every sentence ends with a period (.) and that each sentence begins with an uppercase letter; for example:
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.';
My attempts:
v_desc := regexp_replace(v_desc,'This product*{2,}','') ;
v_desc := regexp_replace(v_desc,'This product*{2,}*','') ;
Desired results
v_desc := 'This product is used. Product may make you wealthy.';
Try this:
Here’s the break down:
This will end up searching for all Instances of “This product …” that is not at the beginning of the line.
*Edit after comment
Then what you want is a positive look behind
(?<=). It should look like this:Breakdown:
It will only trigger the next value as true if the expression “This product …” is before it. This will prevent the first occurrence of “This product” from showing up in the values to be replaced.
I would like to point out, that the lookaheads and lookbehinds are not supported on all implantation of Regex. I don’t know the specifics of PL/SQL, so I cannot guarantee this will work. It does work when I test on Regex Hero.