diff --git a/UnitsNet.Tests/CustomCode/ParseTests.cs b/UnitsNet.Tests/CustomCode/ParseTests.cs index 3fb03de1a0..2067dae1d7 100644 --- a/UnitsNet.Tests/CustomCode/ParseTests.cs +++ b/UnitsNet.Tests/CustomCode/ParseTests.cs @@ -41,6 +41,7 @@ public class ParseTests [InlineData("1e-3 km", 1)] [InlineData("5.5 m", 5.5)] [InlineData("500,005 m", 500005)] + [InlineData("NaN m", double.NaN)] public void ParseLengthToMetersUsEnglish(string s, double expected) { CultureInfo usEnglish = new CultureInfo("en-US"); @@ -235,4 +236,4 @@ private static string AssertExceptionAndGetFullTypeName(Action code) } } -} \ No newline at end of file +} diff --git a/UnitsNet/CustomCode/QuantityParser.cs b/UnitsNet/CustomCode/QuantityParser.cs index 7835bf8b72..1bf935becd 100644 --- a/UnitsNet/CustomCode/QuantityParser.cs +++ b/UnitsNet/CustomCode/QuantityParser.cs @@ -63,7 +63,7 @@ internal static TQuantity Parse([NotNull] string str, string unitsRegex = $"({String.Join("|", unitAbbreviations)})"; - string regexString = string.Format(@"(?:\s*(?[-+]?{0}{1}{2}{3})?{4}{5}", + string regexString = string.Format(@"(?:\s*(?(?:[-+]?{0}{1}|NaN){2}{3})?{4}{5}", numRegex, // capture base (integral) Quantity value exponentialRegex, // capture exponential (if any), end of Quantity capturing @"\s?", // ignore whitespace (allows both "1kg", "1 kg")