<div id="out"></div> <script> let s='a_4_8_15_16 , b_23_42'; // и т.д. for(s of s.matchAll(/[^,\s]+/g)){ s = s[0].match(/[a-z]|_\d+/g) out.append(JSON.stringify(s)) }; </script>