Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 313701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:07:56+00:00 2026-05-12T08:07:56+00:00

I am trying to detect the browser in my C# code by comparing the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:07:56+00:00Added an answer on May 12, 2026 at 8:07 am

    You should use something like this in C#:

    string 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)";
    string ieRegEx = @"^Mozilla/4.0 \(compatible; MSIE ([0-9\.]+); Windows .*\)$";
    bool success = Regex.Match(sampleUserAgent, ieRegEx, RegexOptions.IgnoreCase).Success;
    

    Note I prefer using correct type identifiers rather than var for simple types.

    Also, I personally would just stick to using Browser Caps as it would be much less hassle, especially if you aren’t good with reg-ex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to detect when the onresize event ends in a browser. If I
I'm trying to use mtrace to detect memory leaks in a fortran program. I'm
I'm trying to figure out a way to detect files that are not opened
I'm trying to detect the position of the browser's scrollbar with JavaScript to decide
I'm trying to get the onreadystate value from the browser control do detect when
I'm trying to detect and change browser behavior if a user clicks on the
I'm trying to detect the size of the screen I'm starting emacs on, and
I am trying to detect which web in sharepoint that the user is looking
I'm trying to figure out how to detect the type of credit card based
I'm trying to determine how I can detect when the user changes the Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.