Regex oRegex = new Regex(@"test[a-zA-z]");
string st = @"this is a test1 and testA and test[abc] another testB and test(xyz) again.";
foreach(Match match in oRegex.Matches(st))
{
Console.WriteLine(match.Value);
}
输出:
测试A
测试[
测试B
问题:为什么test[
在输出中?字符类 [a-zA-Z] 应该只匹配字母字符 a 到 z 和 A 到 Z。