var str = '10000000000000000 1000.00' alert(str.replace(/\.(\d{2}($|\b))/g, ',$1').replace(/(\d)(?=(\d{3})+(\.|$|\b))/g, '$1.'))