JSFiddle - React, Tailwind, and code Playground
JavaScript
var yourString = "sss your string 'this is safe' and this is not";
var tokens = yourString.split("");
var inQuotes = false;
for(var i=0;i<tokens.length;i++){
if(tokens[i] == "'"){
inQuotes = !inQuotes;
}else
if(!inQuotes && tokens[i] == 's'){
tokens[i] = 'p'
}
}
var result = tokens.join("");
document.body.innerHTML = result;