fork(2) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string pattern = @"^((?(D)(?!))(?<C>1)|(?(D)(?!))(?<-C>0)|(?(C)(?!))(?<D>0)|(?(C)(?!))(?<-D>1))*(?(C)(?!))(?(D)(?!))$";
  9.  
  10. string[] matchedStrings = new[] { "1100", "1010", "0101", "11000011" };
  11. string[] unmatchedStrings = new[] { "110", "001", "1100001" };
  12.  
  13. foreach (var s in matchedStrings)
  14. Console.WriteLine("Should matching {0}: {1}", s, Regex.IsMatch(s, pattern));
  15. foreach (var s in unmatchedStrings)
  16. Console.WriteLine("Should not matching {0}: {1}", s, !Regex.IsMatch(s, pattern));
  17. }
  18. }
Success #stdin #stdout 0.07s 34064KB
stdin
Standard input is empty
stdout
Should matching 1100: True
Should matching 1010: True
Should matching 0101: True
Should matching 11000011: True
Should not matching 110: True
Should not matching 001: True
Should not matching 1100001: True