PostgreSQL replace range of unicode chars
I have some problems with characters not allowed in XML-export. The request is simply to remove the invalid characters from the text to ensure corrext export/import of data.
so far, thanks to this post I have an sql statement which replaces one declared Unicode char:
UPDATE mytable SET myproperty = replace(myproperty, U&'\UNICODE', '');
It removes the specified Unicode from all occurrences inside the defined cell. But I would like to give a bunch of Unicode chars to be replaced, eg. 0x1 - 0xf Does anybody have an idea how to achieve that?
Use TRANSLATE to remove multiple characters:
TRANSLATE(myproperty, 'list of characters', '');
Normally it's used to replace characters, but if the replacement string is empty it's removing them.
Of course you can also use a regular expression, this allows ranges of characters:
regexp_replace(myproperty, '[\u0041-\u0043a]', '', 'g')
Adding the 'g' flag to replace all occurrences...