Regex 正则表达式,查找匹配项
这个正则表达式给出了计数的答案3。 我怎么能在“你好”之前只吃第一个和第二个“一些”? 请帮帮我Regex 正则表达式,查找匹配项,regex,Regex,这个正则表达式给出了计数的答案3。 我怎么能在“你好”之前只吃第一个和第二个“一些”? 请帮帮我 string SomeText ="Some some hello some" string patternSome = @"some"; RegexOptions RegOptions = RegexOptions.IgnoreCase |RegexOptions.CultureInvariant; Regex newRegex = new Regex(patternSome, RegOpti
string SomeText ="Some some hello some"
string patternSome = @"some";
RegexOptions RegOptions = RegexOptions.IgnoreCase |RegexOptions.CultureInvariant;
Regex newRegex = new Regex(patternSome, RegOptions );
MatchCollection matches = newRegex.Matches(SomeText);
Console.WriteLine("Count of matches {0}", matches.Count);
您可以使用lookahead regex:
\b[Ss]ome\b(?=.*hello)
这将匹配
some
或some
,前提是后面跟一个hello
您可能想包括这是什么语言。:)