fork(4) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace RegexAABBCC
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string re = @"(?:(?(1)(?!))(hell)|(?(2)(?!))(hello)|(?(3)(?!))(foo))+";
  11.  
  12. string[] txt = {
  13. "foo",
  14. "hellhello",
  15. "foohellohell",
  16. "hellhellohell",
  17. "foohellohellfoo",
  18. };
  19.  
  20. foreach (string s in txt)
  21. {
  22. Match m = Regex.Match(s, re);
  23.  
  24. if (m.Success == true)
  25. {
  26. Console.WriteLine("Matched: \"{0}\" \tin: \"{1}\"", m.Value, s);
  27. }
  28. else
  29. {
  30. Console.WriteLine("Not matched: \"{0}\"", s);
  31. }
  32. }
  33.  
  34. Console.ReadKey();
  35. }
  36. }
  37. }
Success #stdin #stdout 0.07s 34072KB
stdin
Standard input is empty
stdout
Matched:     "foo" 	in: "foo"
Matched:     "hellhello" 	in: "hellhello"
Matched:     "foohell" 	in: "foohellohell"
Matched:     "hellhello" 	in: "hellhellohell"
Matched:     "foohell" 	in: "foohellohellfoo"