let test = ` #1 js,100元 # #12 java,1000元 # #sds dsdjsi # ddw #6 php,120元 # ` let handler = test.match(/#\d+\s+.+\s+#$/gm); handler = handler.map((item)=>{ let h = item.replace(/#/,'').replace(/\s+#/,'').split(','); [name,price] = h; return {name,price}; }) console.log(handler);