jQuery - Regex to remove spaces from a string

To remove a single blank or space character, you must use the replace() which repeats this regex:

var text = "this is a \n text \t."; 
text = text.replace(/ /g,'');
console.log(text);
Runtime:

thisestun
text.
the character g defines the repetition of the search through the entire string. This regular expression removed white space but left line breaks and \t.

If you want to remove all white space and not just the blank character, use \s like this:

text = text.replace(/\s/g,''); 
Execution:

thisisuntext.