Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Replacing a word with regexp_replace()

Scott SwankJul 19 2018 — edited Jul 19 2018

I can find a word pretty easily with a pattern like (^|\W)whatever($|\W). But if I use that pattern to replace a word, I also replace the non-word characters that correspond to \W.

In the case below I lose the space before "this" as well as the question mark after it. Is there a better way to swap out a single word in a line of  text?

select regexp_replace('What is this?', '(^|\W)this($|\W)','that') replaced

from dual;

Note that I only want whole words. If I'm replacing "this" with "that", I do not want to match "thistle".

My larger project is address normalization, e.g. Boulevard --> Blvd, East --> E, etc.

Thanks all.

This post has been answered by Solomon Yakobson on Jul 19 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 16 2018
Added on Jul 19 2018
6 comments
3,110 views