fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ExtensionExtractingTest
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string fileNames = "test.docxtest2.txttest3.pdftest.test.xlxtest.docxtest2.txttest3.pdftest.test.xlxtest.docxtest2.txttest3.pdftest.test.xlxourtest.txtnewtest.pdfstackoverflow.pdf";
  14. Regex fileNameMatchRegex = new Regex(@"[a-zA-Z0-9]*(\.txt|\.pdf|\.docx|\.txt|\.xlx)", RegexOptions.IgnoreCase);
  15. MatchCollection matchResult = fileNameMatchRegex.Matches(fileNames);
  16. List<string> fileNamesList = new List<string>();
  17. foreach (Match item in matchResult)
  18. {
  19. fileNamesList.Add(item.Value);
  20. }
  21. fileNamesList = fileNamesList.Distinct().ToList();
  22. Console.WriteLine(string.Join(";", fileNamesList));
  23. }
  24. }
  25. }
  26.  
Success #stdin #stdout 0.13s 24752KB
stdin
Standard input is empty
stdout
test.docx;test2.txt;test3.pdf;test.xlx;ourtest.txt;newtest.pdf;stackoverflow.pdf