public static bool TryParse()

in resharper/resharper-unity/src/Unity/UnityEditorIntegration/VersionUtils/JetSemanticVersionRange.cs [73:134]


        public static bool TryParse(string expression, [MaybeNullWhen(false)] out JetSemanticVersionRange range)
        {
            range = null;

            // An empty expression means match everything
            if (string.IsNullOrEmpty(expression))
            {
                range = new JetSemanticVersionRange(JetSemanticVersion.Empty, null, true, true);
                return true;
            }

            if (expression.Contains(" ")) return false;

            var fromInclusive = expression.StartsWith("[");
            var fromExclusive = expression.StartsWith("(");
            var toInclusive = expression.EndsWith("]");
            var toExclusive = expression.EndsWith(")");

            // If we have an opening bracket, we need a closing bracket
            if ((fromExclusive | fromInclusive) != (toExclusive | toInclusive))
                return false;

            var startIdx = expression.StartsWith("[") || expression.StartsWith("(") ? 1 : 0;
            var endIdx = expression.EndsWith("]") || expression.EndsWith(")") ? 1 : 0;
            expression = expression.Substring(startIdx, expression.Length - startIdx - endIdx);

            var versions = expression.Split(',');
            if (JetSemanticVersion.TryParse(versions[0], out var fromVersion))
            {
                // 1.2.3 => x >= 1.2.3
                // [1.2.3] => x = 1.2.3
                // [1.2.3) - invalid
                // (1.2.3] - invalid
                // (1.2.3) - invalid
                if (versions.Length == 1)
                {
                    // [1.2.3] => x = 1.2.3
                    if (fromInclusive && toInclusive)
                    {
                        range = new JetSemanticVersionRange(fromVersion, fromVersion, fromInclusive, toInclusive);
                        return true;
                    }

                    // 1.2.3 => x >= 1.2.3
                    if (!fromInclusive && !fromExclusive && !toInclusive && !toExclusive)
                    {
                        range = new JetSemanticVersionRange(fromVersion, null, true, false);
                        return true;
                    }
                    
                    return false;
                }

                if (JetSemanticVersion.TryParse(versions[1], out var toVersion))
                {
                    range = new JetSemanticVersionRange(fromVersion, toVersion, fromInclusive, toInclusive);
                    return true;
                }
            }

            return false;
        }