왜이 표현식은 탐욕적인 접근 방식을 따르지 않고 있습니까?왜이 표현식은 탐욕적인 접근 방식을 따르지 않습니까?
string input = @"cool man! your dog can walk on water ";
string pattern = @"cool (?<cool>(.*)) (?<h>((dog)*)) (?(h)(?<dog>(.*))) ";
MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
foreach (Match match in matches)
{
Console.WriteLine("cool=" + match.Groups["cool"].Value);
Console.WriteLine("dog=" + match.Groups["dog"].Value);
Console.ReadLine();
}
출력 :
cool= man! your dog can walk on water dog=
당신이 관찰 할 수 있듯이 : (개) 그룹은 이후 0 짤리을 일치, *은 최대 일치를 찾으려고하지 않는 이유, 욕심 1의 (개)?
실마리가 있습니까?
? 욕심을 제한합니다. –