'esversion: 6';
function myReplace(str, before, after) {
var re = new RegExp(before);
return before[0] === before[0].toLowerCase() ? str.replace(re, after)
: str.replace(re, after.charAt(0).toUpperCase() + after.slice(1));
}
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");