HI to all,
I am in need of escaping the regular expression special characters like '/', '.', '*', '+', '?', '|','(', ')', '', '{', '}', '\\'.
I have try with this by the following javascript but i can not achieve that.
RegExp.escape=function(str)
{
if (!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'gim'
);
}
return str.replace(arguments.callee.sRE, '\\');
}
function regExpFind() {
// var regex = new RegExp("\\[munees\\]","gim");
var regex=RegExp.escape("[Munees]waran");
alert("Reg : "+regex);
alert(regex.exec("[Munees]waran"));
}
If i go with the line which is commented,
var regex = new RegExp("\\[munees\\]","gim");
I have the correct output.
But by with the replace method i cannot achieve that?
Please guide me to achieve that.