title: Escaping a Javascript string, Unterminated character class error
body: <p>I keep getting the following error</p>
  
  <pre><code>Uncaught SyntaxError: Invalid regular expression: /$_POST['/: Unterminated character class 
  </code></pre>
  
  <p>I searched a few threads and they all pointed me to the fact the at I am not properly escaping the string.
  I loaded a php file into a javascript var as a string , then I search through it for the following, but I have tried escaping to no success.</p>
  
  <p>according to <a href="https://stackoverflow.com/questions/5105143/list-of-all-characters-that-should-be-escaped-before-put-in-to-regex">List of all characters that should be escaped before put in to RegEx?</a></p>
  
  <p>These are all the characters that need escaping I believe.</p>
  
  <pre><code>. \ + * ? [ ^ ] $ ( ) { } = ! &lt; &gt; | : -
  </code></pre>
  
  <p>and here are the code snipets that are failing me. (This is the clean code everything needs escaping)</p>
  
  <pre><code>var n = data.search("$_POST['");
  n = res.search("'];");
  n = data.search("//hurdle{"); 
  n = res.search("}");
  </code></pre>
  
  <p>If someone could show me how to properly do this, it would be very appreciated. Thank you</p>