Q:

Java Regular Expression; need to map \' to ''

I'm trying to map the \' to ''. That is, a string consisting of a backslash followed immediately by a single quote should be mapped to two single quotes.
I've tried using 
string = string.replace("\'", "''")

but this also maps a single quote to two single quotes (i.e., "'" to "''"), which is incorrect for what I need. What am I doing wrong?

A:

Backslash here is a escape character and it just will match ' if you want to match \' you need \\':
string = string.replace("\\'", "''")

