I’ve got a regex that looks for a <span> with the class name foobar. It works in IE9, Chrome and Firefox. It’s failing in IE7 and IE8. Can anyone tell me why?
new RegExp( /(\s*?)<span\b(?:.*?)(?:class=(?:'|"|.*?\s)?foobar(?:\s|\3))(?:.*?)(?:\/)?>(.+?)<\/span>(\s*?)/g )
If you’re applying the regex against html you got from getElementById().innerHTML or jQuery .html(), IE will uppercase the HTML tags which could be the problem. If you make the regex case-insensitive – that is, change the modifier
/gto/giat the end – does that fix it ?It seems like you’re also mixing the regex literal and RegExp object syntax, you can do it with just the regex literal instead.