cari

Rumah  >  Soal Jawab  >  teks badan

javascript - masalah padanan biasa js

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中文网PHP中文网2741 hari yang lalu362

membalas semua(2)saya akan balas

  • PHP中文网

    PHP中文网2017-05-16 13:05:28

    ganti(/+/g, ","")

    balas
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:05:28

    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"]

    balas
    0
  • Batalbalas