Skip to content

Instantly share code, notes, and snippets.

@travissanon
Created September 23, 2017 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travissanon/9b0247c573dc1a7953b9f551ad365029 to your computer and use it in GitHub Desktop.
Save travissanon/9b0247c573dc1a7953b9f551ad365029 to your computer and use it in GitHub Desktop.
'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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment