如何使用正则表达式组查找多个匹配项?

为什么以下代码会导致:

“ the”有1个匹配项

并不是:

“ the”有3个匹配项

using System;

using System.Text.RegularExpressions;

namespace TestRegex82723223

{

class Program

{

static void Main(string[] args)

{

string text = "C# is the best language there is in the world.";

string search = "the";

Match match = Regex.Match(text, search);

Console.WriteLine("there was {0} matches for '{1}'", match.Groups.Count, match.Value);

Console.ReadLine();

}

}

}

回答:

string text = "C# is the best language there is in the world.";

string search = "the";

MatchCollection matches = Regex.Matches(text, search);

Console.WriteLine("there was {0} matches for '{1}'", matches.Count, search);

Console.ReadLine();

以上是 如何使用正则表达式组查找多个匹配项? 的全部内容, 来源链接: utcz.com/qa/430078.html

回到顶部