Regex for Escaping Regex Characters
str = str.replace(/([\\\^\$*+[\]?{}.=!:(|)])/g,"\\$1"); where str is a string which will be passed to the RegExp() constructor.
str = str.replace(/([\\\^\$*+[\]?{}.=!:(|)])/g,"\\$1"); where str is a string which will be passed to the RegExp() constructor.