Skip to content

Regex "^aA$" does not match "aA" for danish culture using IgnoreCase in 3.1 #32534

@soverkaer

Description

@soverkaer

In 3.1 (tested with 3.1.2 on Windows) there seem to be a regression in regular expression matching for danish culture when using IgnoreCase.

For example, for this program:

public static void Main(string[] args)
{
    Match("^aA$", "aA", "da-DK", RegexOptions.IgnoreCase);
    Match("^aa$", "aA", "da-DK", RegexOptions.IgnoreCase);
    Match("^aA$", "aA", "da-DK", RegexOptions.IgnoreCase | RegexOptions.Compiled);
    Match("^aa$", "aA", "da-DK", RegexOptions.IgnoreCase | RegexOptions.Compiled);
    Match("^aA$", "aA", "da-DK", RegexOptions.None);
    Match("^aa$", "aA", "da-DK", RegexOptions.None);
}

public static void Match(string pattern, string text, string culture, RegexOptions options)
{
    CultureInfo.CurrentCulture = new CultureInfo(culture);

    var regex = new Regex(pattern, options);

    Console.WriteLine($"{pattern}/{text}/{culture}/{options}: {regex.IsMatch(text)}");
}

When targeting netcoreapp2.1 (or net461) this prints:

^aA$/aA/da-DK/IgnoreCase: True
^aa$/aA/da-DK/IgnoreCase: True
^aA$/aA/da-DK/IgnoreCase, Compiled: True
^aa$/aA/da-DK/IgnoreCase, Compiled: True
^aA$/aA/da-DK/None: True
^aa$/aA/da-DK/None: False

When targeting netcoreapp3.1 this prints:

^aA$/aA/da-DK/IgnoreCase: False
^aa$/aA/da-DK/IgnoreCase: False
^aA$/aA/da-DK/IgnoreCase, Compiled: True
^aa$/aA/da-DK/IgnoreCase, Compiled: True
^aA$/aA/da-DK/None: True
^aa$/aA/da-DK/None: False

This seem to be caused by the changes in RegexBoyerMoore in dotnet/corefx#30632, as string.Compare("aa", 0, "aA", 0, 2, true, new CultureInfo("da-DK")) returns 1.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions