I forgott the / which is also to escape with javascript !
Code:
String.prototype.toRegExp=function(){return this.replace(/\\/g,'\\\\').replace(/(\[|\^|\$|\.|\||\?|\*|\+|\(|\)|\/)/g,'\\$1')}
//Example of use with all the «meta»characters
var something="[\\^$.|?*+()/"; // the slashe is to escape
alert(("foo"+something+"bar").replace(new RegExp(something.toRegExp(),'g'),''));// =>'foobar'