我正在使用正则表达式,我写了这个:
static void Main(string[] args)
{
string test = "this a string meant to test long space recognition n a";
Regex regex = new Regex(@"[a-z][\s]{4,}[a-z]$");
MatchCollection matches = regex.Matches(test);
if (matches.Count > 1)
Console.WriteLine("yes");
else
{
Console.WriteLine("no");
Console.WriteLine("the number of matches is "+matches.Count);
}
}
在我看来,Matches 方法应该同时找到“n n”和“n a”。尽管如此,它只能找到“n n”,我只是不明白为什么会这样..