この式が貪欲なアプローチに従っていないのはなぜですか?
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();
}
出力:
クール=男!あなたの犬は水の上を歩くことができます 犬=
あなたが観察できるように: (犬) グループは 0 回一致します。
手がかりはありますか?