如何使用javascript转义正则表达式特殊字符?
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() { <%--var regex = new RegExp("\\[munees\\]","gim");--%> var regex= new RegExp(RegExp.escape("[Munees]waran")); <%--var regex=RegExp.escape`enter code here`("[Munees]waran");--%> alert("Reg : "+regex); }
Qyouu