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

  • Home
  • SEARCH
  • 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 830155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:59:52+00:00 2026-05-15T03:59:52+00:00

I have the following C# code which should match a quantity / $ price

  • 0

I have the following C# code which should match a quantity / $ price string like “4/$3.99”. It works all day long until we use it against a string returned from Firefox Browser. 77.77 becomes 77 (dropping the .77 cents).

var matches = Regex.Match(_priceText, 
    @"^\s?((?<qty>\d+)\s?/)?\s?[$]?\s?(?<price>[0-9]?\.?[0-9]?[0-9]?)");

if( matches.Success)
{
    if (!Decimal.TryParse(matches.Groups["price"].Value, out this._price))
        this._price = 0.0m;
    if (!Int32.TryParse(matches.Groups["qty"].Value, out this._qty))
        this._qty = (this._price > 0 ? 1 : 0);
    else
        if (this._price > 0 && this._qty == 0)
            this._qty = 1;
}

Any idea why the period wouldn’t match coming from a Firefox string, but the C# string matches? There isn’t any special about the Firefox we used. It’s a plain Jane 1252 code page download right off the Firefox site. The computer’s local settings are unaltered North American, etc. We have two different computers showing the same effects. It’s Firefox 3.6.4, nothing fancy or beta.

  • 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-15T03:59:53+00:00Added an answer on May 15, 2026 at 3:59 am

    Firefox isn’t the problem. The pattern is incomplete.

    Try this pattern instead:

    @"^\s?((?<qty>\d+)\s?/)?\s?[$]?\s?(?<price>[0-9]{1,2}\.?[0-9]?[0-9]?)"
    

    The problem in the original pattern is the (?<price>[0-9]?\.?[0-9]?[0-9]?) portion. The problem you described occurs with any number that starts with 2 digits, not just Firefox values. Your sample was 4/$3.99 but 4/$33.99 would cause the same issue. The [0-9]?\.?[0-9]?[0-9]? part matches a digit followed by a period. Unfortunately the pattern is littered with optional ? metacharacters after almost everything and that is why this bug has popped up. For 77.77 it matches the first 7 then it should match a dot but wait, there’s a second 7 and no dot (which is optional \.?) so it happily skips it. Next the pattern expects 2 optional digits, but it sees a dot and stops, thus returning only 77. That’s the general idea.

    Having said that, you should lay out precisely what inputs are valid when constructing the pattern. Your original pattern indicates that the price group is entirely optional. Look at it closely; everything has a ? appended to it. So what are your goals? Is it optional? Are whole numbers allowed? Must it be a decimal with a .xy in the number? My proposed pattern at the top used [0-9]{1,2} to force 1-2 numbers to exist, while leaving the .xy portion optional.

    If the .xy portion is truly optional you could update your price group to this: (?<price>\d{1,2}(?:\.\d{1,2})?) – that way the optional ? metacharacter applies to everything that is optional and is only specified once. This makes the pattern more readable IMO. The (?:...) portion is optional (specifically usage of ?: not the actual grouping) but it’s good practice to avoid capturing the group unnecessarily. With these changes in place the new pattern would be:

    @"^\s?((?<qty>\d+)\s?/)?\s?[$]?\s?(?<price>\d{1,2}(?:\.\d{1,2})?)"
    

    Notice that the pattern still has issues, depending on what your requirements are. The entire qty group is optional, meaning the 4/ part could be omitted from the input and an input of $3.99 would be valid. If this is required then don’t make it optional:

    @"^\s?((?<qty>\d+)\s?/)\s?[$]?\s?(?<price>\d{1,2}(?:\.\d{1,2})?)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 476k
  • Answers 476k
  • 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 I believe the problem has to do with the double-quotes… May 16, 2026 at 4:53 am
  • Editorial Team
    Editorial Team added an answer You cannot inject a <script> element using .innerHTML and expect… May 16, 2026 at 4:53 am
  • Editorial Team
    Editorial Team added an answer The basic idea should be straightforward: Server: doPost(HttpServletRequest req, HttpServletResponse… May 16, 2026 at 4:53 am

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.