I want to replace two or more occurrences of whitespace with just one whitespace character using JavaScript (this code is going to sit inside a chrome extension).
3 Answers
You can do both at once with:
"str str\t\t\tstr".replace(/(\s)+/g, "$1"); 3 Comments
Davide
Didn't know that \s matched \t as well. Impressive!
Max
@Davide how would I go about replacing tabs with space now? do I do an other loop?
deviousdodo
If you want all white space characters replaced by a space, you should simply use what davin wrote. I added my example because I thought you wanted multiple tabs to be replaced by a tab, multiple spaces by a space, etc.