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 strs = new List<string> { "First: 12345Z Apr 16 Something WORD: ABC Notification #1234 Key1 Key2 Key3 Key4",
  12. "Second: 12345Z Apr 16 Something WORD: ABC Notification #1234 Key5 Key3 Key6",
  13. "Third: 12345Z Apr 16 Something WORD: ABC Notification #1234 Key7 Key6"};
  14. foreach (var s in strs) {
  15. var result = Regex.Matches(s, @"(?<=#\d{4}(?:\s+\w+)*)\s*\b(Key3|Key4|Key6|Key7)\b")
  16. .Cast<Match>()
  17. .Select(m => m.Value)
  18. .ToList();
  19. foreach (var e in result)
  20. Console.WriteLine(e);
  21. }
  22. }
  23. }
Success #stdin #stdout 0.17s 24728KB
stdin
Standard input is empty
stdout
 Key3
 Key4
 Key3
 Key6
 Key7
 Key6