@@ -284,17 +284,14 @@ namespace UnitsNet
284
284
(NumberFormatInfo) formatProvider.GetFormat(typeof (NumberFormatInfo)) :
285
285
NumberFormatInfo.CurrentInfo;
286
286
287
- var numRegex = string.Format("{0}{1}{2}{3}",
288
- @"[\d., ", // allows digits, dots, commas, and spaces in the number by default
289
- numFormat.NumberGroupSeparator, // adds provided (or current) culture's group separator
290
- numFormat.NumberDecimalSeparator, // adds provided (or current) culture's decimal separator
291
- @"]*\d"); // ensures quantity ends in digit
292
- var regexString = string.Format("{0}{1}{2}{3}{4}",
293
- @"(?<value>[-+]?", // start capturing Quantity
294
- numRegex, // parse base (integral) Quantity value
295
- @"(?:[eE][-+]?\d+)?)", // capture Quantity exponential (if any), end capturing Quantity
296
- @"\s?", // ignore whitespace (allows both "1kg", "1 kg")
297
- @"(?<unit>\S+)"); // capture Unit (non-whitespace) input
287
+ var numRegex = string.Format(@"[\d., {0}{1}]*\d", // allows digits, dots, commas, and spaces in the quantity (must end in digit)
288
+ numFormat.NumberGroupSeparator, // adds provided (or current) culture's group separator
289
+ numFormat.NumberDecimalSeparator); // adds provided (or current) culture's decimal separator
290
+ var regexString = string.Format("(?<value>[-+]?{0}{1}{2}{3}",
291
+ numRegex, // capture base (integral) Quantity value
292
+ @"(?:[eE][-+]?\d+)?)", // capture exponential (if any), end of Quantity capturing
293
+ @"\s?", // ignore whitespace (allows both "1kg", "1 kg")
294
+ @"(?<unit>\S+)"); // capture Unit (non-whitespace) input
298
295
299
296
var regex = new Regex(regexString);
300
297
GroupCollection groups = regex.Match(str.Trim()).Groups;
0 commit comments