var replace = function(str, bef, aft) { var reg = new RegExp(bef, "g"); return str.replace(reg, aft); };