Repository: dotnet/runtime
File: src/libraries/System.Data.OleDb/src/DbConnectionOptions.cs (C#)

Code before:
            + "[\\s;]*[\u0000\\s]*"                                     // trailing whitespace/semicolons (DataSourceLocator), embedded nulls are allowed only in the end
        ;

        private const string ConnectionStringPatternOdbc =              // may not contain embedded null except trailing last value
            "([\\s;]*"                                                  // leading whitespace and extra semicolons
            + "(?![\\s;])"                                              // key does not start with space or semicolon
            + "(?<key>([^=\\s\\p{Cc}]|\\s+[^=\\s\\p{Cc}])+)"            // allow any visible character for keyname except '='
            + "\\s*=\\s*"                                               // the equal sign divides the key and value parts
            + "(?<value>"
            + "(\\{([^\\}\u0000]|\\}\\})*\\})"                         // quoted string, starts with { and ends with }
            + "|"
            + "((?![\\{\\s])"                                          // unquoted value must not start with { or space, would also like = but too late to change
            + "([^;\\s\\p{Cc}]|\\s+[^;\\s\\p{Cc}])*"                  // control characters must be quoted

            + ")" // although the spec does not allow {}
                  // embedded within a value, the retail code does.
                  // +  "(?<![\\}]))"                                            // unquoted value must not stop with }

            + ")(\\s*)(;|[\u0000\\s]*$)"                               // whitespace after value up to semicolon or end-of-line
            + ")*"                                                      // repeat the key-value pair
            + "[\\s;]*[\u0000\\s]*"                                     // trailing whitespace/semicolons (DataSourceLocator), embedded nulls are allowed only in the end
        ;


        private static readonly Regex ConnectionStringRegex = CreateConnectionStringRegex;
        private static readonly Regex ConnectionStringRegexOdbc = CreateConnectionStringRegexOdbc();

#if NET
        [GeneratedRegex(ConnectionStringPattern, RegexOptions.ExplicitCapture)]
        private static partial Regex CreateConnectionStringRegex { get; }

        [GeneratedRegex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture)]
        private static partial Regex CreateConnectionStringRegexOdbc { get; }
#else
        private static Regex CreateConnectionStringRegex() => new Regex(ConnectionStringPattern, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
        private static Regex CreateConnectionStringRegexOdbc() => new Regex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
#endif
#endif
        internal const string DataDirectory = "|datadirectory|";

        private static readonly Regex ConnectionStringValidKeyRegex = CreateConnectionStringValidKeyRegex; // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
        private static readonly Regex ConnectionStringQuoteValueRegex = CreateConnectionStringQuoteValueRegex; // generally do not quote the value if it matches the pattern
        private static readonly Regex ConnectionStringQuoteOdbcValueRegex = CreateConnectionStringQuoteOdbcValueRegex; // do not quote odbc value if it matches this pattern

#if NET
        [GeneratedRegex("^(?![;\\s])[^\\p{Cc}]+(?<!\\s)$")]
        private static partial Regex CreateConnectionStringValidKeyRegex { get; }
        [GeneratedRegex("^[^\"'=;\\s\\p{Cc}]*$")]
        private static partial Regex CreateConnectionStringQuoteValueRegex { get; }
        [GeneratedRegex("^\\{([^\\}\u0000]|\\}\\})*\\}$", RegexOptions.ExplicitCapture)]
        private static partial Regex CreateConnectionStringQuoteOdbcValueRegex { get; }

Review comment (suggestion):
The call site for `CreateConnectionStringRegexOdbc` still uses method call syntax `()` but it was converted to a property. It should be `CreateConnectionStringRegexOdbc` (without parentheses) to match the property declaration on line 67.
```suggestion
        private static readonly Regex ConnectionStringRegexOdbc = CreateConnectionStringRegexOdbc;
```

Code after:
            + "[\\s;]*[\u0000\\s]*"                                     // trailing whitespace/semicolons (DataSourceLocator), embedded nulls are allowed only in the end
        ;

        private const string ConnectionStringPatternOdbc =              // may not contain embedded null except trailing last value
            "([\\s;]*"                                                  // leading whitespace and extra semicolons
            + "(?![\\s;])"                                              // key does not start with space or semicolon
            + "(?<key>([^=\\s\\p{Cc}]|\\s+[^=\\s\\p{Cc}])+)"            // allow any visible character for keyname except '='
            + "\\s*=\\s*"                                               // the equal sign divides the key and value parts
            + "(?<value>"
            + "(\\{([^\\}\u0000]|\\}\\})*\\})"                         // quoted string, starts with { and ends with }
            + "|"
            + "((?![\\{\\s])"                                          // unquoted value must not start with { or space, would also like = but too late to change
            + "([^;\\s\\p{Cc}]|\\s+[^;\\s\\p{Cc}])*"                  // control characters must be quoted

            + ")" // although the spec does not allow {}
                  // embedded within a value, the retail code does.
                  // +  "(?<![\\}]))"                                            // unquoted value must not stop with }

            + ")(\\s*)(;|[\u0000\\s]*$)"                               // whitespace after value up to semicolon or end-of-line
            + ")*"                                                      // repeat the key-value pair
            + "[\\s;]*[\u0000\\s]*"                                     // trailing whitespace/semicolons (DataSourceLocator), embedded nulls are allowed only in the end
        ;


#if NET
        [GeneratedRegex(ConnectionStringPattern, RegexOptions.ExplicitCapture)]
        private static partial Regex ConnectionStringRegex { get; }

        [GeneratedRegex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture)]
        private static partial Regex ConnectionStringRegexOdbc { get; }
#else
        private static Regex ConnectionStringRegex { get; } = new Regex(ConnectionStringPattern, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
        private static Regex ConnectionStringRegexOdbc { get; } = new Regex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
#endif
#endif
        internal const string DataDirectory = "|datadirectory|";

#if NET
        [GeneratedRegex("^(?![;\\s])[^\\p{Cc}]+(?<!\\s)$")]
        private static partial Regex ConnectionStringValidKeyRegex { get; } // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
        [GeneratedRegex("^[^\"'=;\\s\\p{Cc}]*$")]
        private static partial Regex ConnectionStringQuoteValueRegex { get; } // generally do not quote the value if it matches the pattern
        [GeneratedRegex("^\\{([^\\}\u0000]|\\}\\})*\\}$", RegexOptions.ExplicitCapture)]
        private static partial Regex ConnectionStringQuoteOdbcValueRegex { get; } // do not quote odbc value if it matches this pattern
#else
        private static Regex ConnectionStringValidKeyRegex { get; } = new Regex("^(?![;\\s])[^\\p{Cc}]+(?<!\\s)$", RegexOptions.Compiled); // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
        private static Regex ConnectionStringQuoteValueRegex { get; } = new Regex("^[^\"'=;\\s\\p{Cc}]*$", RegexOptions.Compiled); // generally do not quote the value if it matches the pattern
        private static Regex ConnectionStringQuoteOdbcValueRegex { get; } = new Regex("^\\{([^\\}\u0000]|\\}\\})*\\}$", RegexOptions.ExplicitCapture | RegexOptions.Compiled); // do not quote odbc value if it matches this pattern
#endif

        // connection string common keywords