I have the following very simple regex, which matches HTML tags in a string. I have the case insensitive option set, so that capitalisation of the tags doesn’t matter. However, when the ‘compiled’ option is set, then the ‘IgnoreCase’ option seems to be ignored.
Sample code:
string text = "<SPAN>blah</SPAN><span>blah</span>";
Regex expr1 = new Regex("</*span>", RegexOptions.IgnoreCase);
Regex expr2 = new Regex("</*span>", RegexOptions.IgnoreCase & RegexOptions.Compiled);
MatchCollection result1 = expr1 .Matches(text);
//gives 4 matches- <SPAN>,</SPAN>,<span> & </span>
MatchCollection result2 = expr2 .Matches(text);
//only gives 2 matches- <span> & </span>
Has anybody got an idea what is going on here?
You are using a bitwise AND for your flags, you should be using a bitwise OR.
This bit:
Should be:
Here is a good article on how flags and enumerations work in respect to C#.