In your case, I would write a function that escapes any character that could have a special meaning in a regexp, applies the regexp and returns the result:
String.prototype.exclude = function(blacklist) {
for(var i=0; i<blacklist.length; i++) {
if(blacklist[i].match(/\W/)) {
blacklist[i] = '\\'+blacklist[i];
}
}
return this.replace(new RegExp('['+blacklist.join('')+']', 'g'), '');
};
var myString = "j a\nv\ra?s!c;r.i,p`t:I(s)A{w}e[s]o|m'e\\~=@><&%-/#";
myString.exclude([' ', '\r', '\n', '?', '!', ';', '.', ',', '`', ':', '(', ')', '{', '}', '[', ']', '|', '\'', '\\', '~', '=', '@', '>', '<', '&', '%', '-', '/', '#']);
// returns "JavascriptIsAwesome" which is of course the correct answer