早い話、PerlにおけるquotemetaがあればOK、と。

文字列から正規表現を生成するときのメモ - IT戦記
という感じで、バックスラッシュをいっぱい書かなければいけないので
perldoc -f quotemeta
quotemeta

Returns the value of EXPR with all non-"word" characters backslashed. (That is, all characters not matching /[A-Za-z_0-9]/ will be preceded by a backslash in the returned string, regardless of any locale settings.) This is the internal function implementing the \Q escape in double-quoted strings.

なら、話は簡単。

String:
Quotemeta:
String.prototype.quotemeta = function(){
  return this.replace(/([^0-9A-Za-z_])/g, '\\$1');
}

で、ぐぐると前に作ってましたね。

Enjoy!

Dan the Wheel Re-inventor