using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { private static Regex _regex = new Regex("c.*?w.*?w"); static void Main(string[] args) { var target = Console.ReadLine(); var r = _regex.Matches(target); if (r == null) { Console.WriteLine("-1"); return; } var i = 101; foreach (Match c in r) { if (i > c.Length) i = c.MatcheEx(_regex).Value.Length; } Console.WriteLine(i); Console.ReadKey(); } } public static class MatchEX { public static Match MatcheEx(this Match match, Regex regex) { var target = match.Value.Substring(1); var search = regex.Matches(target); if(search.Count == 0) { return match; } else if (search.Count == 1) { return search[0].MatcheEx(regex); } else { throw new Exception("too match"); } } } }