let test = ` #1 js,200元 # #2 php,300元 # #9 hou # 后盾人 #6 java,1000元 # `; let handler = test.match(/^\s+#\d+\s+.+\s+#$/gm); let res = handler.map((item)=>{ let i = item.replace(/\s+#\d+\s+/,'').replace(/#/,''); [name,price] = i.split(','); return { name,price }; }) console.log(res)