using System; using System.Text.RegularExpressions; namespace RegexAABBCC { class Program { static void Main(string[] args) { string re = @"(?:(?(1)(?!))(hell)|(?(2)(?!))(hello)|(?(3)(?!))(foo))+"; string[] txt = { "foo", "hellhello", "foohellohell", "hellhellohell", "foohellohellfoo", }; foreach (string s in txt) { Match m = Regex.Match(s, re); if (m.Success == true) { Console.WriteLine("Matched: \"{0}\" \tin: \"{1}\"", m.Value, s); } else { Console.WriteLine("Not matched: \"{0}\"", s); } } Console.ReadKey(); } } }