Skip to content

Commit 7b0a1f0

Browse files
committed
Updated regex format strings
1 parent 3b5fd71 commit 7b0a1f0

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Src/Scripts/Include-GenerateUnitClassSourceCode.ps1

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,14 @@ namespace UnitsNet
284284
(NumberFormatInfo) formatProvider.GetFormat(typeof (NumberFormatInfo)) :
285285
NumberFormatInfo.CurrentInfo;
286286
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
298295
299296
var regex = new Regex(regexString);
300297
GroupCollection groups = regex.Match(str.Trim()).Groups;

0 commit comments

Comments
 (0)