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 const string CWW = "c.*?w.*?w"; static void Main(string[] args) { var target = Console.ReadLine(); var regex = new Regex(CWW); var index = 0; var roopEnd = false; var result = -1; do { var match = regex.Match(target, index); if (match.Success) { index = match.Index + 1; var tmp = match.Value.Length; result = (result == -1) ? tmp : Math.Min(result, tmp); } else { roopEnd = true; } } while (roopEnd == false); Console.WriteLine(result); Console.ReadKey(); } } }