Created
May 15, 2017 12:32
-
-
Save cristinaITdeveloper/8fcc12820ddf2b9469df9a1b65354609 to your computer and use it in GitHub Desktop.
Javascript replace all character in string
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
function escapeRegExp(str) { | |
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); | |
} | |
function replaceAll(str, find, replace) { | |
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment