forgot that js replace only works on first match, so switch to re so it works well.