function escapeRegExp(string){ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } var string = "abbb ccc"; var a = "Abbb"; var reg = new RegExp(escapeRegExp(a),"i"); string = string.replace(reg, ""); alert(string);