title: Invalid regular expression: /(/: Unterminated group
body: <p>I want to create a function that removes all unwanted characters from a text. This is what I came up with, but it doesn´t work:</p>
  <pre><code>var invalid = &quot;^°\&quot;§%()[]{}=\\?´`'#&lt;&gt;|,;.:-+_&quot;;
  
  for (var n = 0; n &lt; invalid.length; n++) 
  {
     var r = new RegExp(invalid[n],&quot;g&quot;);
     toCheck.replace(r,&quot;&quot;);
  } 
  </code></pre>