in reply to parsing multi-line output from a cli command
If the summary is always on a single line and is the second line you could always put the second line directly in the summary and the first line could be parsed for input. If not you will have to take that into account.
What charachters are allowed to appear in the summary? If any charachters can appear and the summary can be multiple lines and it's on a second line because the code is wrapping you will have problems, because you can't split on charachters such as [, ], or :. If you have access to the code of the original CLI you may want to change the output a little bit. I would recommend outputting the results to XML if it's an option. That would make it much easier for you and whoever else needs to parse it to parse it.
Otherwise you may need to get tricky if the worse case scenario for everything I've mentioned is true. You could split on the regular expression: /^.*: [.*?\] \[.*?\] \[.*?\] \[.*?\].*$/ (I think, not tested). You'd then have all of the comments. Or you could read line by line and use that regular expressiong with the $`, $&, $' variables. (That's the thing before the match, the thing that was matched, and the thing after the match). Be warned though that once they're present in code they will be created for all regular expressions which can slow down your code.
Just some thoughts,
Vautrin
|
|---|