I'm faced with a need for parsing a string into key-value pairs, where the value may be optional. Standard command line parsers are not useful, because all the ones I checked accept a String[] and not a String. Thus, I resorted to regex, and sure enough, faced with the following:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
First, the input string:
"/opt/sensu/embedded/bin/ruby /opt/sensu/embedded/bin/check-graphite-stats.rb " +
"--crit 25 --host 99.99.999.9999:8082 --period -5mins --target 'alias(scale(divideSeries(" +
"summarize(sumSeries(nonNegativeDerivative(transformNull(exclude(" +
"\\\"unknown\\\"), 0))), \\\"30d\\\", \\\"sum\\\", false),summarize(" +
...gigantuous string
\\\"sum\\\", false)), 100), \\\"3pp error rate\\\")' " +
"--unknown-ignore --warn 5"
Next, my regex:
(--(?<option>.+?)\s+(?<value>.+?(?=--))?)+?
the above almost works, but not quite.
Output:
--crit 25
--host 99.99.999.9999:8082
--period -5mins
--target 'gigantuous string'
--unknown-ignore
--warn
Why is the value of --warn not picked up?
args[]?