Created
November 25, 2013 09:22
-
-
Save jlcampana/7638733 to your computer and use it in GitHub Desktop.
String Replace sin expresiones regulares
This file contains hidden or 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
/** | |
* | |
* Javascript string replace | |
* http://www.webtoolkit.info/ | |
* | |
**/ | |
// standart string replace functionality | |
function str_replace(haystack, needle, replacement) { | |
var temp = haystack.split(needle); | |
return temp.join(replacement); | |
} | |
// needle may be a regular expression | |
function str_replace_reg(haystack, needle, replacement) { | |
var r = new RegExp(needle, 'g'); | |
return haystack.replace(r, replacement); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment