regex to replace backslash and single quote with single quote using postgres regexp_replace() regex to replace backslash and single quote with single quote using postgres regexp_replace() postgresql postgresql

regex to replace backslash and single quote with single quote using postgres regexp_replace()


This is relatively straightforward. Note that both the backslash character \ as well as the single-quote character ' (which you escaped in the OP) need to be escaped. The difference is that the backslash has to be escaped in the regex itself, whereas the single quote is escaped in the string literal. Anyway, enough of that digression.

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

Hope this helps.


You can try the following:

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

Edit: of course \''+ is better

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