JSFiddle - React, Tailwind, and code Playground JavaScript var t = "AA-12,AB-1,AC-11,AD-8,AE-30"; alert(t.match(/\d+/g).join(','));