My table has a column MSG_INFO
with sample data:
Party is carrying gold in a car which is made of ,gold,
Party is carrying whitegold in a car which made of gold
I need a SQL expression that searches for gold
and if there is an exact match then I append ~
after the first character of the exact match gold
and no action to be performed when there is no exact match.
gold
can only be surrounded by space or comma on either side.
Expected output:
Party is carrying g~old in a car which is made of ,g~old,
Party is carrying whitegold in a car which made of g~old
Note - After inserting ~
space before and after gold should still be preserved.
This is what I've started with:
SELECT REGEXP_REPLACE (msg_info, '(^|\s|\W)(gold)($|\s|\W)', '\1~\2\3', 1,0,'i')
FROM table;
Party is carrying ~gold in a car which is made of ,~gold,
Party is carrying whitegold in a car which made of ~gold
It correctly identifies the correct instances of gold
but it puts the ~
before the word rather than after the first character.