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> { "ABC-210293CompletedReports",
  12. "CC517036submittedbyfoobarforABC105799WRS877565",
  13. "ABC#86765",
  14. "abc99220 / 103743",
  15. "AbC99220/103743",
  16. "ABC 123 and 1123",
  17. "SubmittedbyFooBar.forABC106156.Solutionbuilton4/23/20184:22PM"
  18. };
  19. var pattern = new Regex(@"(?i)\d{1,2}/\d{1,2}/\d{4}|(ABC.\d{1,11}| *(?:[/-]|AND) *\d{1,11})", RegexOptions.Compiled);
  20. foreach (var s in strs) {
  21. var results = pattern.Matches(s)
  22. .Cast<Match>()
  23. .Select(m => m.Groups[1].Value)
  24. .ToList();
  25. foreach (var t in results)
  26. Console.WriteLine(t);
  27. } }
  28. }
Success #stdin #stdout 0.07s 20544KB
stdin
Standard input is empty
stdout
ABC-210293
ABC105799
ABC#86765
abc99220
 / 103743
AbC99220
/103743
ABC 123
 and 1123
ABC106156