In this case, you really do not need regular expressions, but if you want to avoid invalid characters in your expression, you should avoid this:
RegExp.quote = function(str) { return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); };
Using:
var re = new RegExp(RegExp.quote(filter));
Without regex, you could do this:
if (query.indexOf(filter) != -1) { }
Ja͢ck source share