//定义正则 let regx = /^\,*|\,*$/g; let str = ",1,2,3,4,5,6,7,8,9,"; console.log(str.replace(regx,' ')); 运行结果