Regex to replace backslash and single quote single quote using postgres regexp_replace ()

Just as the title says, I'm not the best w / regex, so anyone can provide the appropriate regex for the following:

UPDATE table SET column = REGEXP_REPLACE(column, {regex}, '''');

Basically, I would like to replace any instances of backslashes ( \), followed by one or more single quotes with one separate quote.

So, the line Hello World\'sor Hello World\'''''sshould become Hello World's, but not Hello World\s.

+4
source share
2 answers

. , \, ' ( OP) . , , . , .

UPDATE table SET column = REGEXP_REPLACE(column, '\\''+', '''', 'g');

, .

+5

:

SELECT REGEXP_REPLACE(column, '\\''['']*', '''','g') from table

: '' +

SELECT REGEXP_REPLACE(column, '\\''+', '''','g') from table
+3

All Articles