Fixed with costs > 1mil

Javascript string replace only replaces first substring by default.
Changed to regular expression