I am trying to detect the browser in my C# code by comparing the UserAgent string with some regular expressions.
By the way, in case you are wondering, the reason why I use this approach instead of simply using ASP.NET's HttpBrowserCapabilities object is because I have received a list of more than 200 regex that correspond to 200 browsers and their OS and I can get more detailed information.
Here's a sample:
var sampleUserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
var ieRegEx = "/^Mozilla\/4.0 \(compatible; MSIE ([0-9\.]+); Windows/si";
var success = Regex.Match(sampleUserAgent, regEx.RegularExpression, RegexOptions.IgnoreCase).Success;
In this example I am expecting the regex match to be successful but for some reason, the match returns false. I am guessing that the regex is not quite right.
I didn't write the regex and I am not very familiar with the RegEx syntax so can anybody help me figure out what is wrong with the regex?