I'm trying to replace the apostrophes I have in strings to double apostrophes for a SQL query, I'm using str.replace(), but I'm messing something up, or I don't have the regex correct.
var tester = "O'neal is walkin'";
tester = tester.replace("'", "$&'");
console.log(tester);
// exp: O''neal is walkin''
// actual: O''neal is walkin'
I thought this might have to do with the apostrophe, but it seems to work that way for all end character edits:
var tester = "O'neal is walkin";
tester = tester.replace("n", "$&g");
console.log(tester);
// exp: O'ngeal is walking
// actual: O'ngeal is walkin
So what am I doing wrong here as to not catch that final character correctly?