You have been referred to this item:

Regex for Escaping Regex Characters

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