var arr = ["abc'def", "abc''de'f"]; for (i=0; i<arr.length; i++) { console.log( arr[i] + ' => ' + arr[i].replace(/(^|[^'])'(?!')/g, "$1''") ); }