Very simple example:
select regexp_replace('This is the place for them to exist, isn''t it?', '(^| )((the)|(is))( |$)', '\1!\5', 1, 0, 'i')rr FROM dual;
This ! the place for them to exist, isn't it?
As you can see, only "is" is replaced and "the" stays as is.
Adding "x" to the match parameter does not help because it replaces all occurrences of "the" and "is" instead replacing only words
select regexp_replace('This is the place for them to be, isn''t it?', '(^| )((the)|(is))( |$)', '\1!\5', 1, 0, 'ix')rr FROM dual;
Th! ! ! place for !m to ex!t, !n't it?
So, the only way I know is to double spaces and then dedup it
select replace(regexp_replace(replace('this is the place for them to exist, isn''t it?',' ',' ') , '(^| )((the)|(is))( |$)', '\1!\5', 1, 0, 'i'),' ',' ')rr from dual;
this ! ! place for them to exist, isn't it?
Is there a way to do it without manipulating spaces??