title: How to properly escape characters in regexp
body: <p>I want to do a string search inside a string. Simply saying <code>MySTR.search(Needle)</code>.</p>
  
  <p>The problem occurs when this <code>needle</code> string contains special regex characters like *,+ and so on. It fails with error <code>invalid quantifier</code>.</p>
  
  <p>I have browsed the web and found out that string can be escaped with <code>\Q some string \E</code>.</p>
  
  <p>However, this does not always produce the desired behavior. For example:</p>
  
  <pre><code>var sNeedle = '*Stars!*';
  var sMySTR = 'The contents of this string have no importance';
  sMySTR.search('\Q' + sNeedle + '\E');
  </code></pre>
  
  <p>Result is -1. OK.</p>
  
  <pre><code>var sNeedle = '**Stars!**';
  var sMySTR = 'The contents of this string have no importance';
  sMySTR.search('\Q' + sNeedle + '\E');
  </code></pre>
  
  <p>Result is "invalid quantifier". This happens because 2 or more special characters are 'touching' each other, because:</p>
  
  <pre><code>var sNeedle = '*Dont touch me*Stars!*Dont touch me*';
  var sMySTR = 'The contents of this string have no importance';
  sMySTR.search('\Q' + sNeedle + '\E');
  </code></pre>
  
  <p>Will work OK.</p>
  
  <p>I know I could make a function <code>escapeAllBadChars(sInStr)</code> and just add double slashes before every possible special regex character, but I'm wondering if there is a simpler way to do it?</p>