SO - 22504393

by Arun P Johny

JavaScript

var str = "This is 'fisrt text' and now this is 'second', and many more contents goes here.";

var map = {
    "'fisrt text'": "'some text'",
    "'second'": "'more text'"
}

var str2 = str.replace(/'.*?'/g, function (str) {
    return map[str] || ''
});
console.log(str2)