0

I am facing the following problem - I want to use REGEXP_REPLACE to replace the occurrences of all kind of symbols after a given string. Suppose I have the string:

I will send you the parcel today.
best regards (may contain multiple new lines)
Tom

I want to replace everything after 'best regards' with 'someone' so that the output gets:

I will send you the parcel today.
best regards
someone

I tried with:

(best regards)[\w\W]*

but it doesn't seem to work and only best regards gets replaced. Since I thought that the problem was with the new line , I transformed the expression into:

(best regards)[\w\W|\r|\n|\f]*

but it still doesn't work. I tried the expression using : https://www.freeformatter.com/regex-tester.html and it did work.

The column is of type CLOB.

William Robertson
  • 15,273
  • 4
  • 38
  • 44
newbie
  • 31
  • 6
  • Could you tell me how to add it? – newbie Apr 06 '18 at 10:39
  • You may use a `.*` to match any chars as many as possible incl. a newline. See https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions130.htm. Everything is explained: *`'n'` allows the period (`.`), which is the match-any-character character, to match the newline character. If you omit this parameter, the period does not match the newline character.* – Wiktor Stribiżew Apr 06 '18 at 10:39
  • So, I have to write it like : REGEXP_REPLACE(input, '(best regards).*' ,'sOMEONE',1, 'n', 1) – newbie Apr 06 '18 at 10:42
  • See http://rextester.com/NFIH76859 – Wiktor Stribiżew Apr 06 '18 at 10:46
  • Oracle and freeformatter use different regex engines. Do not rely on regex tools much if you are not sure if the regex engine they use is compatible with yours. – Wiktor Stribiżew Apr 06 '18 at 11:02

0 Answers0