fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var strings = new List<string> { "1 abcd", "abcd 1", "1 abcd 1"};
  12. var pattern = "(^)?abcd(?(1)|$)";
  13. foreach (var s in strings)
  14. {
  15. Console.WriteLine("{0} => {1}", s, Regex.IsMatch(s, pattern));
  16. }
  17. }
  18. }
Success #stdin #stdout 0.05s 20964KB
stdin
Standard input is empty
stdout
1 abcd => True
abcd 1 => True
1 abcd 1 => False