Fix String.prototype.replace when used with global regexp