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

Ask A Question

Stats

  • Questions 209k
  • Answers 209k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer yes, implement a custom state session-provider. And no, afaik there… May 12, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer This is solvable on the client with Javascript. PHP isn't… May 12, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer Actually there is a way to customize DataTemplates as they… May 12, 2026 at 9:41 pm

Related Questions

I have a flash object that takes up the whole browser on my website.
I am trying to detect which web in sharepoint that the user is looking
I am trying to detect three operating systems - Windows XP, Windows Vista, Linux.
I am trying to find data within a HTML document. I don't need a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.