I thought the community helped me nail this problem w/a case insensitive RegExp, but I got it wrong. What about the following RegEx fails in IE7 and IE8?
var reggy = /(\s*?)<span\b(?:.*?)(?:class=(?:'|"|.*?\s)?foobar(?:\s|\3))(?:.*?)(?:\/)?>(.+?)<\/span>(\s*?)/ig;
jsFiddle here. Only in IE7 and IE8 does it give a “did not match” result.
There are several problems with that regex, the worst of them being that you seem to be mixing up capturing and non-capturing groups. As Mike Samuel hinted, the third capturing group is the
(\s*?)at the very end (which, like the one at the beginning, served no useful purpose). Try this regex:Here there’s only the one capturing group; it captures a single-quote, a double-quote, or nothing. After the class name, the
\1matches the same thing again. (I changed the class name to match the sample text in your fiddle.)It turned out I didn’t need any other groups, but if I had needed them I would have used non-capturing groups (
(?:...)) to make it easier to keep track of the capturing-group numbers. I also used[\s\S]instead of.to match the span’s contents, in case it contains any newlines.