不知道为什么我无法在C#中匹配这个正则表达式

Dej*_*jas 2 .net c# regex

我正在尝试将字符串"9月12日"与以下C#代码匹配.但它不匹配,我不知道为什么.我究竟做错了什么?它似乎适用于regexpal.com

public static void Scan(String str)
    {
        String digits = "(0|1|2|3|4|5|6|7|8|9)";

        String r1 = "September " + digits + "+";

        foreach (Match match in Regex.Matches(str, r1, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace))
        {
            String value = match.Value;
        }


    }
Run Code Online (Sandbox Code Playgroud)

Mor*_*oth 7

问题是标志RegexOptions.IgnorePatternWhitespace.删除它,因为你不想忽略正则表达式中的空格 - 你需要它来匹配"九月"和"19"之间的空格.

提示:digits可以写得更容易[0-9].一个更好的正则表达式将是

September [0-9]+
Run Code Online (Sandbox Code Playgroud)