110,566
社区成员
发帖
与我相关
我的任务
分享
string str = @"怎么学才能学好
你要怎么做才能给我钱
你要怎么做阿佐才能给我钱";
Regex regex = new Regex(@"(?=(怎么))[\u4e00-\u9fa5]*(?=(才能))[\u4e00-\u9fa5]*");
MatchCollection mc = regex.Matches(str);
foreach (Match item in mc)
{
Console.WriteLine("index:" + item.Groups[1].Index + " " + item.Groups[1].Value + " index:" + item.Groups[2].Index + " " + item.Groups[2].Value);
}
(?=(怎么))
谢谢了
string str = @"怎么学才能学好
你要怎么做才能给我钱
你要怎么做阿佐才能给我钱";
Regex regex = new Regex(@"(?=(怎么))[\u4e00-\u9fa5]*(?=(才能))[\u4e00-\u9fa5]*");
MatchCollection mc = regex.Matches(str);
int index = 0;
foreach (Match item in mc)
{
Console.WriteLine("index:"+index+" "+item.Groups[1].Value + " index:"+ index +" " + item.Groups[2].Value);
index++;
}