String.split() and backtracking in IE7
handgestrickt hoped that the Microsoft-team that is responsible for the JScript-Engine fixed the backtracking- or parenthesis- bug in Internet Explorer 7. if you use a regular expression with parenthesis in String.split() in Internet Explorer, the matches for the parenthesized expressions are not returned in the resulting array. this is very annoying, especially when you want to write good parsers in JavaScript. we wanted to write an HTMLbeautifier, so we had to parse HTML quick and dirty. we will release this beautifier later. here is the fix for the annoying bug. feel free to use it.
var foo = {
splitFix: function(string,regexp) {
var matches = [];
if(!document.all || window.opera) matches = string.split(regexp);
else {
var delim = '<#%fuckIE!>'; //lol
var prnth = String(regexp).replace(/\(\?/g,'');
prnth = prnth.replace(/[^\(]+/g,'').length;
var repl = delim;
for(var a=0;a<prnth;a++) repl += '$<span>'</span>+(a+1)+delim;
eval("string = string.replace("+regexp+"g,repl);");
matches = string.split(delim);
}
return matches;
}
}

