简体   繁体   中英

C# regex match always return false

Here are my test case for c# regex match:

AAA
BB
AAA+15d
BB-205w

The pattern i have used is: @"^(AAA|BB)([\\+|\\-]\\d+[d|w])*$" , when i test it online in some .net regex tester, it says match. but when i run it in c# codes, always return false for the last two test cases. What is wrong with the pattern?

i can't reproduce the mentioned behaviour

List<string> Input = new List<string>() { "AAA", "BB", "AAA+15d", "BB-205w" };
string Pattern = @"^(AAA|BB)([+-]\d+[dw])*$";
foreach (string item in Input)
{
    Console.WriteLine(Regex.IsMatch(item, Pattern));
}

Result:

True 
True 
True 
True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM