You can use callback
"1,234.56".replace(/[.,]/g, function(x) { return x == ',' ? '.' : ','; });
Fiddle
If you intend to replace more than two characters, you can create a convenient function using the card to replace
function swap(str, swaps) { var reg = new RegExp('['+Object.keys(swaps).join('')+']','g'); return str.replace(reg, function(x) { return swaps[x] }); } var map = { '.':',', ',':'.' } var result = swap("1,234.56", map);
Fiddle
source share