I need to escape the regular expression special characters using java script.How can i achieve this?Any help should be appreciated.(我需要使用java脚本转义正则表达式特殊字符。如何实现这一点?任何帮助都应该被理解。)
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.(感谢您的快速回复。但我需要逃避正则表达式的所有特殊字符。我已经尝试了这段代码,但我无法达到结果。)
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);
}
What i am wrong with this code?Please guide me.(这段代码我错了什么?请指导我。)
ask by Muneeswaran Balasubramanian translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…