title: How to escape regular expression special characters using javascript?
body: <p>I need to escape the regular expression special characters using java script.How can i achieve this?Any help should be appreciated.</p>
  
  <hr>
  
  <p>Thanks for your quick reply.But i need to escape all the special characters of regular expression.I have try by this code,But i can't achieve the result.</p>
  
  <pre><code>RegExp.escape=function(str)
              {
                  if (!arguments.callee.sRE) {
                      var specials = [
                          '/', '.', '*', '+', '?', '|',
                          '(', ')', '[', ']', '{', '}', '\\'
                      ];
                      arguments.callee.sRE = new RegExp(
                      '(\\' + specials.join('|\\') + ')', 'gim'
                  );
                  }
                  return str.replace(arguments.callee.sRE, '\\$1');
  
              }
  
  function regExpFind() {
              &lt;%--var regex = new RegExp("\\[munees\\]","gim");--%&gt;
                      var regex= new RegExp(RegExp.escape("[Munees]waran"));
                      &lt;%--var regex=RegExp.escape`enter code here`("[Munees]waran");--%&gt;
                      alert("Reg : "+regex);
                  }
  </code></pre>
  
  <p>What i am wrong with this code?Please guide me.</p>