alert( "2-3-6-6".replace(/(^-\d+)?((-\d+)+)/g,function(a,b,c){return (b||'')+ c.replace(/-/g,'')})  ) 这里的+)+)第一个加号感觉多余。

解决方案 »

  1.   

    关于function已经找到答案document.close();
    document.open();var str = "123abc";
    str = str.replace(/(.)(.)(.)/g, function(all, one, two, three) {
    document.write("all:" + all + "<br/>");
    document.write("one:" + one + "<br/>");
    document.write("two:" + two + "<br/>");
    document.write("three:" + three + "<br/>");
    });((-\d+)+)这加号是不是有点多余?
      

  2.   


    \d+ 匹配 1~n个数字
    ((-\d+)+) 1~n个 -\d+
      

  3.   

    var string = "-2-3-6-7-6";
    var number = /(-\d)+/g;
    document.write(string.match(number));var string = "-2-3-6-7-6";
    var number = /-\d+/g;
    document.write(string.match(number));