这样恐怕不行,你要在每一段之间加上特殊标记,然后split

解决方案 »

  1.   


           function parse(str) {
                var result = [];
                var arr = str.split("|");
                for (var i = 0; i <= arr.length / 5; i++) {
                    var person = [];
                    person.push(arr[i * 5 + 1]);
                    person.push(arr[i * 5 + 2]);
                    person.push(arr[i * 5 + 3]);
                    person.push(arr[i * 5 + 4]);
                    person.push(arr[i * 5 + 5]);                result.push(person);
                }            return result;
            }
      

  2.   

    试试var strContact = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]",
        reg = /(\|[^|]+){4}\|\w+@\w+\.(?:com|cn|org|net)/gi,
        rs,
        person = [];
    rs = strContact.match(reg);
    if(rs){
        for(var i=0,il=rs.length;i<il;i++){
            person.push(rs[i].substring(1).split(/\|/))
        }
    }
      

  3.   


    function showResult() {
                var strContact = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]";
                var strList = strContact.split("|");            var personInfo = "";
                var arr = new Array();            var reg = /[,]$/;
                for (var i = 1, len = strList.length; i <= len; i++) {
                    if (strList[i] != "") {
                        personInfo += '"' + strList[i] + '",';
                    }
                    if (i % 5 == 0) {
                        var str = personInfo.replace(/[,]$/, "");
                        arr.push(str);
                        personInfo = "";
                    }
                }            /* 结果:
                    "联系人ID1","张三","010-88888888","13666666666","[email protected]"
                    "联系人ID2","李四","010-88888888","13666666666","[email protected]"
                    "联系人ID3","王五","010-88888888","13666666666","[email protected]"
                */
                return arr;
            }
      

  4.   


    <script type="text/javascript">
    var s = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]
    var t=s.split("|");
    var c=(t.length-1)/5;
    var b=new Array()
    var d=new Array();
    for(var i=1;i<t.length;i++){
    d[i-1]=t[i];
    }
    var q=0;
    for(var j=0;j<c;j++){
    b[j]=new Array();
    for(var i=0;i<((t.length-1)/c);i++){
    b[j][i]=d[i+q*5];
    }
    q++;
    }
    alert(b["0"]);
    alert(b["1"]);
    alert(b["2"]);
    </script>