I want to replace all occurrences of white space characters (space, tab, newline) in JavaScript. How to do so?
I tried:
str.replace(/ /gi, "X")
You want s
s
Matches a single white space character, including space, tab, form feed, line feed.
Equivalent to
[ f vu00a0u1680u2000-u200au2028u2029u202fu205fu3000ufeff]
in Firefox and [ f v] in IE.
[ f v]
str = str.replace(/s/g, "X");
2.1m questions
2.1m answers
60 comments
57.0k users