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();
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpuYW1lc3BhY2UgUmVnZXhBQUJCQ0MKewogICAgY2xhc3MgUHJvZ3JhbQogICAgewogICAgICAgIHN0YXRpYyB2b2lkIE1haW4oc3RyaW5nW10gYXJncykKICAgICAgICB7CiAgICAgICAgICAgIHN0cmluZyByZSA9IEAiKD86KD8oMSkoPyEpKShoZWxsKXwoPygyKSg/ISkpKGhlbGxvKXwoPygzKSg/ISkpKGZvbykpKyI7CiAgICAgICAgICAgIAogICAgICAgICAgICBzdHJpbmdbXSB0eHQgPSB7CiAgICAgICAgICAgICAgICAiZm9vIiwKICAgICAgICAgICAgICAgICJoZWxsaGVsbG8iLAogICAgICAgICAgICAgICAgImZvb2hlbGxvaGVsbCIsCiAgICAgICAgICAgICAgICAiaGVsbGhlbGxvaGVsbCIsCiAgICAgICAgICAgICAgICAiZm9vaGVsbG9oZWxsZm9vIiwKICAgICAgICAgICAgfTsKCiAgICAgICAgICAgIGZvcmVhY2ggKHN0cmluZyBzIGluIHR4dCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgTWF0Y2ggbSA9IFJlZ2V4Lk1hdGNoKHMsIHJlKTsKCiAgICAgICAgICAgICAgICBpZiAobS5TdWNjZXNzID09IHRydWUpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIk1hdGNoZWQ6ICAgICBcInswfVwiIFx0aW46IFwiezF9XCIiLCBtLlZhbHVlLCBzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiTm90IG1hdGNoZWQ6IFwiezB9XCIiLCBzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgQ29uc29sZS5SZWFkS2V5KCk7CiAgICAgICAgfQogICAgfQp9