fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var strs = new List<string>() { "Boy has a dog and a cat.",
  10. "Boy something a gerbil.",
  11. "Sally owns a cat." };
  12. foreach (var s in strs)
  13. {
  14. var results = Regex.Matches(s, @"(?<=^Boy\b.*?)\b(?:dog|cat|gerbil)\b")
  15. .Cast<Match>()
  16. .Select(m => m.Value)
  17. .ToList();
  18. if (results.Count > 0) {
  19. Console.WriteLine("{0}:\n[{1}]\n------", s, string.Join(", ", results));
  20. }
  21. else
  22. {
  23. Console.WriteLine("{0}:\nNO MATCH!\n------", s);
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 0.04s 134720KB
stdin
Standard input is empty
stdout
Boy has a dog and a cat.:
[dog, cat]
------
Boy something a gerbil.:
[gerbil]
------
Sally owns a cat.:
NO MATCH!
------