August 10, 2009
jQuery Replace craziness
I spent way too much time figuring this out.
var originalString = “Batman And Robin”;
var replacedSpaces = originalString.replace(‘ ‘, ‘_’);
This doesn’t work, it only replaces the first instace of the match, so replacedSpaces == “Batman_And Robin”.
var replacedSpaces = originalString.replace(/ /g, ‘_’);
This does work, and now replacedSpaces == “Batman_And_Robin”.
CategoryUncategorized
0 Comments
Sign in to join the conversation
Sign inBe the first to comment.