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