I am forced into parsing some HTML on the client side (and yes this really is the only option in this case), but I am having a bit of trouble in Firefox only with the following:
$('#Extensions').load('/advanced/admin/config.php?type=setup&display=extensions #container li'
,function(){
$('li').each(function(){
var liRow=$(this).html();
var reExten=/([0-9]+)/g;
var extension = liRow.match(reExten)[0]
var reName=/>([a-zA-z0-9\s]+ *)/g;
var matchName = reName.exec(liRow);
var name = matchName[1]
});
}
);
The HTML that is being returned from load is something along the lines of:
<a href="file.php?type=A&extension=1001">Test Extension <1001></a>
The regex seems to work fine if you copy and paste it into the firefox JS console and the code as a whole works fine in internet explorer 7/8/9.
So here’s the tricky bit. In firefox matchName is null on every other iteration of .each. Example output from Firebug:
LOG: Matches: The Boss
LOG: data: <A href="file.php?type=A&extension=13">The Boss <13></A>
LOG: regex: />([a-zA-z0-9\s]+ *)/g;
LOG: Matches: Test Extension
LOG: data: <A href="file.php?type=A&extension=1001">Test Extension <1001></A>
LOG: regex: />([a-zA-z0-9\s]+ *)/g;
LOG: Matches: John Smith
LOG: data: <A href="file.php?type=A&extension=3801">John Smtih<3801></A>
LOG: regex: />([a-zA-z0-9\s]+ *)/g;
LOG: Matches: Guy Smiley
LOG: data: <A href="file.php?type=A&extension=3802">Guy Smiley <3802></A>
LOG: regex: />([a-zA-z0-9\s]+ *)/g;
LOG: Matches: 3803
LOG: data: <A href="file.php?type=A&extension=3803">Jane Doe <3803></A>
LOG: regex: /extdisplay=([0-9]+)/g
LOG: Matches: 3804
LOG: data: <A href="file.php?type=A&extension=3804">John Doe <3804></A>
LOG: regex: />([a-zA-z0-9\s]+ *)/g;
Lastly, this only seems to happen when using re.exec and never on str.match(re). I’m at a total loss and have been starting at this for an hour now so I hope the question makes some kind of sense!
This is probably not the final answer but its an easy thing to check. I ran this through JSLint and got these errors. Occasionally things like this can account for browser discrepancies.