fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<string> nomes = new List<string> {
  10. @"Cliente1\Rem\COB0111111.REM.txt",
  11. @"Cliente1\Rem\23123123.REM.txt",
  12. @"Cliente1\OK\COB02222222.REM.txt",
  13. @"Cliente1\Ret\COB0613062019.REM.txt",
  14. "COB0613062019.REM.txt",
  15. @"Cliente2\COB0613062019.REM.txt",
  16. @"Cliente2\Rem\COB0633333.REM.txt",
  17. @"Cliente2\Rem\pasta2\COB02123123.REM.txt",
  18. @"Cliente2\Bla\Rem\COB0613062019.REM.txt",
  19. @"Cliente1\COB0613062019.REM.txt",
  20. @"Rem\COB0613062019.REM.txt",
  21. "Rem",
  22. "Cliente3"
  23. };
  24. List<String> nomesValidos = new List<string>();
  25. Regex regex = new Regex(@"^[^\\]+\\Rem\\([^\\]+)$", RegexOptions.IgnoreCase);
  26. foreach (string nome in nomes)
  27. {
  28. Match match = regex.Match(nome);
  29. if (match.Success)
  30. {
  31. nomesValidos.Add(match.Groups[1].Value);
  32. }
  33. }
  34.  
  35. foreach (string nome in nomesValidos)
  36. {
  37. Console.WriteLine(nome);
  38. }
  39. }
  40. }
Success #stdin #stdout 0.07s 134208KB
stdin
Standard input is empty
stdout
COB0111111.REM.txt
23123123.REM.txt
COB0633333.REM.txt