Changed nonstandard global replace call with regex replace