JSFiddle - React, Tailwind, and code Playground JavaScript var myStr = "John P White"; var matches = myStr.match(/\b(\w)/g); alert(matches.join(''));