JSFiddle - React, Tailwind, and code Playground JavaScript var s = "00012 34 0000432 0035"; var trimmed = s.replace(/\b0+/g, ""); alert(trimmed);