fork download
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Program
  7. {
  8. private static readonly Regex _clRegex = new Regex(
  9. @"^(?<command>blah)((\s+(?<option>--.+?))*(\s+(?<fspec>.*?))*)+$",
  10. RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  11.  
  12. public static void Main(string[] args)
  13. {
  14. string demo = "blah --arg1 --arg2 --etc doh";
  15.  
  16. var sb = new StringBuilder();
  17. foreach (Match m in _clRegex.Matches(demo))
  18. {
  19. foreach (var kind in new [] {"command", "option", "fspec"})
  20. {
  21. var g = m.Groups[kind];
  22. if (g.Success) foreach (Capture cap in g.Captures)
  23. {
  24. switch(kind)
  25. {
  26. case "command": sb.Append(cap); break;
  27. case "fspec": sb.Append(" " + Path.Combine(Directory.GetCurrentDirectory(), cap.Value)); break;
  28. case "option": sb.Append(" " + cap); break;
  29. }
  30. }
  31. }
  32. }
  33.  
  34. Console.WriteLine(sb.ToString().Trim());
  35. }
  36. }
  37.  
Success #stdin #stdout 0.08s 37280KB
stdin
Standard input is empty
stdout
blah --arg1 --arg2 --etc /home/9IjzeN/doh