How to match a period in Regex coming from Firefox browser?
Posted
by Dr. Zim
on Stack Overflow
See other posts from Stack Overflow
or by Dr. Zim
Published on 2010-06-08T23:35:12Z
Indexed on
2010/06/08
23:42 UTC
Read the original article
Hit count: 234
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.
© Stack Overflow or respective owner