JSFiddle - React, Tailwind, and code Playground JavaScript var str = '10000000000'; alert(str.replace(/(\d)(?=(\d{3})+(\D|$))/g, '$1 '));