Just a string. Add \\\' to it every time there is a single quote.
var str = "This is a single quote: ' and so is this: '"; console.log(str); var replaced = str.replace(/'/g, "\\'"); console.log(replaced);
Gives you:
This is a single quote: ' and so is this: ' This is a single quote: \' and so is this: \'