Created
September 23, 2017 04:01
-
-
Save travissanon/9b0247c573dc1a7953b9f551ad365029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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