suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - js正则匹配的问题

用正则匹配,只允许有数字和逗号

var str = "2456789,2345678765432,,,,234567876543,,,45678976543,,,,3456765432";

数字中间的逗号只允许出现一次;多的替换成空;如何写.大神在哪...
希望得到的结果2456789,2345678765432,234567876543,45678976543,3456765432;

PHP中文网PHP中文网2741 Tage vor357

Antworte allen(2)Ich werde antworten

  • PHP中文网

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

    replace(/,+/g, ",")

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

    Antwort
    0
  • StornierenAntwort