[英]Regular expressions, find matches
This regular expression gives answer 3 for count. 该正则表达式给出答案3。 How can I take only first and second "some" before "hello" ?
我怎样才能在“ hello”之前仅取第一和第二“ some”? Help me, please.
请帮帮我。
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);
You can use lookahead regex: 您可以使用前瞻正则表达式:
\b[Ss]ome\b(?=.*hello)
This will match some
or Some
only if it is followed by a hello
. 仅当其后跟一个
hello
它才匹配some
或Some
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.