Regexp Replace - Replacement Problem [message #624915] |
Sun, 28 September 2014 10:52 |
|
wintech
Messages: 2 Registered: September 2014
|
Junior Member |
|
|
Hi,
I want to replace all thy with ish, which are not contained in a word.
I thought i could take \Wthy\W but the second thy is not replaced and also the last one not. Ok the last one because there is noch character left but why not the second?
thx wintech
SELECT REGEXP_REPLACE('healthy, thy thy d , wealthy, and wise thy thy','(\W)thy(\W)', '\1ish\2' ) from dual;
REGEXP_REPLACE('HEALTHY,THYTHYD,WEALTHY,ANDWISETHYTHY','(\W)THY(\W)','\1ISH\2')
-------------------------------------------------------------------------------
healthy, ish thy d , wealthy, and wise ish thy
1 row selected.
|
|
|
Re: Regexp Replace - Replacement Problem [message #624916 is a reply to message #624915] |
Sun, 28 September 2014 11:13 |
|
Michel Cadot
Messages: 68643 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Quote: but why not the second?
Not the second one because the preceding space is gobble up by the preceding " thy " and so the second "thy" does not satisfy the condition.
You have no space followed or preceded by a space you can use:
SQL> SELECT replace(
2 REGEXP_REPLACE(
3 replace('healthy, thy thy d , wealthy, and wise thy thy',' ',' '),
4 '(\W|^)thy(\W|$)', '\1ish\2'),
5 ' ',' ')
6 from dual;
REPLACE(REGEXP_REPLACE(REPLACE('HEALTHY,THYTHY
----------------------------------------------
healthy, ish ish d , wealthy, and wise ish ish
[Updated on: Sun, 28 September 2014 15:27] Report message to a moderator
|
|
|
|