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 text = "\".doc\" \"test.xls\", \".doc\",\"me.pdf\", \"test file.doc\".doc \".doc\"";
  12. Console.WriteLine(text); // => ".doc" "test.xls", ".doc","me.pdf", "test file.doc".doc ".doc"
  13. var pattern = "\"(?<ext>[^\"]+)\"|(?<ext>[^\\s,]+)";
  14. Console.WriteLine(pattern); // => "(?<ext>[^"]+)"|(?<ext>[^\s,]+)
  15. var results = Regex.Matches(text, pattern)
  16. .Cast<Match>()
  17. .Select(x => x.Groups["ext"].Value)
  18. .Distinct();
  19. Console.WriteLine(string.Join("\n", results));
  20. }
  21. }
Success #stdin #stdout 0.06s 22260KB
stdin
Standard input is empty
stdout
".doc" "test.xls", ".doc","me.pdf", "test file.doc".doc ".doc"
"(?<ext>[^"]+)"|(?<ext>[^\s,]+)
.doc
test.xls
me.pdf
test file.doc