I'm looking for a way to remove these characters from a string in javascript (and spaces).
?[]/\=<>:;,'\"&$#*()|~`!{} I am unsure how to construct this:
"mystring is - ?[] hello ".replace(regex, ""); Some elements need escaping, some do not?
Inside a character class [], most don't need escaping:
var pattern = /[?\[\]/\\=<>:;,'"&$#*()|~`!{}]/g; "mystring is - ?[] hello ".replace(pattern, ""); The g flag is added for global replacement.
alert("mystring is -<> ;:,'\"&%^=!{} ?[] hello ".replace(pattern, "")); // Prints: mystring is - %^ hello