Special character checking in JavaScript
I have a string:
var string = "asdasASFASDŞGFSD123435489()/%&&&&&&&&&&&&&&&123435";
I want this string to have a space after any group of ampersands. So in this example, I开发者_JAVA百科 want the output:
"asdasASFASDŞGFSD123435489()/%&&&&&&&&&&&&&&& 123435";
How can I accomplish this in JavaScript?
well, mine is cooler ;)
var string = "asdasASFASDŞGFSD123435489()/%&&&&&&&&&&&&&&&123435";
alert(string.replace(/&+/g, "$& "))
I think this is the job of regular expressions. For example you could do something like this (not tested, just to get the idea):
string.replace("(&+)", "$1 ");
精彩评论