I need to write an SQL text for replacing only entire words.
For "whole word" I mean all occurrences which are not part of another alphanumeric word.
Example:
Replacing 'abc' with 'xyz'
| MYFIELD |
| 'test abc test' |
| 'abctest' |
| 'testabctest' |
| 'testabc' |
| 'abc test' |
| 'test abc' |
| 'abc' |
| ' abc ' |
Expected result:
| MYFIELD |
| 'test xyz test' |
| 'abctest' |
| 'testabctest' |
| 'testabc' |
| 'xyz test' |
| 'test xyz' |
| 'xyz' |
| ' xyz ' |
I've prepared an example using a common regular expression engine.
I've tried porting the same RegEx in Firebird SQL, using SIMILAR TO, but it didn't worked as expected:
UPDATE mytable
SET mytable = REPLACE(myfield, 'abc', 'xyz')
WHERE myfield SIMILAR TO '\babc\b'