gpt4 book ai didi

c# - 如何使用正则表达式组查找多次出现?

转载 作者:IT王子 更新时间:2023-10-29 04:32:14 25 4
gpt4 key购买 nike

为什么下面的代码会导致:

there was 1 matches for 'the'

而不是:

there was 3 matches for 'the'

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();

关于c# - 如何使用正则表达式组查找多次出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3246237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com