Gunakan padanan biasa, hanya nombor dan koma dibenarkan
var str = "2456789,2345678765432,,,,234567876543,,,45678976543,,,,3456765432";
Koma di tengah nombor hanya dibenarkan muncul sekali; gantikan lagi dengan kosong; ;
认证高级PHP讲师
ganti(/+/g, ","")
var re = /\d+\,?/g; var str = "2456789,2345678765432,,,,234567876543,,,45678976543,,,,3456765432"; var myArray = str.match(re); console.log(myArray); VM389472:4 (5) ["2456789,", "2345678765432,", "234567876543,", "45678976543,", "3456765432"]
ganti(/+/g, ","")