var arr = ["pippo%12pluto%_prova", "ori%_aa"]; for (i=0; i<arr.length; i++) { console.log( arr[i] + ' => ' + arr[i].replace(/(^|[^'])'(?!')/g, "$1''") ); }