I did it using LINQ... might not be the best way but it was fun to figure it out:
string test = "<info:\"Enterprise Optimizer 7.4 for COR Technology 5.5 -- Advanced Solver Edition\", url:\"http://EO.riverlogic.com\", url_menu:\"EO Online...\", app_id:\"EOAS\",app_name:\"Enterprise Optimizer AS\", **app_major:7**, **app_minor:4**,**app_micro:5**,app_copyright:\"251 1996-2010 River Logic Inc.\r\nAll Rights Reserved.\">";
var result = test.Split(',').
Select(p => p.Trim().Split(':')).
Where(i => i[0].Trim().StartsWith("**app_")).
Select(r => new { Key = r[0].Trim('*'), Value = r[1].TrimEnd('*') });
Produces:
result = {{Key = "app_major", Value = "7"},
{Key = "app_minor", Value = "4"},
{Key = "app_micro", Value = "5"}}
It could probably even be done much more elegantly :)
EDIT: If you want to make it very simple to access what you want do:
var result = test.Split(',').
Select(p => p.Trim().Split(':')).
Where(i => i[0].Trim().StartsWith("**app_")).
Select(r => new { Key = r[0].Trim('*'), Value = r[1].TrimEnd('*') }).
ToDictionary(k => k.Key, v => v.Value);
Then to get the value out just give it the key like this:
var version = result["app_major"] ?? "Not Found";
Note I have tested the LINQ solution vs the Regex solution and the LINQ version is not that much of a difference in terms of speed but it is a bit slower than the regex answers posted. The regex answer though do not clean the data for you and present it in a easy to use manner. The ToDictionary
part really slows it down (in terms of real time though it is almost nothing still) but it does make the results easier to use.