javascript split regex bug in IE7

前端 未结 2 1177
无人及你
无人及你 2021-01-19 21:41

I am trying to split with this regex ({[^{}]*}) in javascript and I get different result btw IE7 and FF. The firefox result is the right one.

&l         


        
2条回答
  •  花落未央
    2021-01-19 22:09

    I made a solution that works on regex({[^{}]*}) and probably others too.

    function ieSplit(str, separator) {
        var match = str.match(RegExp(separator, 'g'));
        var notmatch = str.replace(new RegExp(separator, 'g'), '[|]').split('[|]');
        var merge = [];
        for(i in notmatch) {
            merge.push(notmatch[i]);
            if (match != null && match[i] != undefined) {
                merge.push(match[i]);
            }
        }
        return merge;
    }
    alert(ieSplit(text, '({[^{}]*})'));
    // result in FF : .box.round ,{border-radius: 10px;},
    // result in IE7: .box.round ,{border-radius: 10px;},
    

提交回复
热议问题