Simple regular expressions should be fine for this.
private Dictionary<string,string> ParseCommentVariables(string contents)
{
Dictionary<string,string> variables = new Dictionary<string,string>();
Regex commentParser = new Regex(@"<!--.+?-->", RegexOptions.Compiled);
Regex variableParser = new Regex(@"\b(?<name>[^:]+):\s*""(?<value>[^""]+)""", RegexOptions.Compiled);
var comments = commentParser.Matches(contents);
foreach (Match comment in comments)
foreach (Match variable in variableParser.Matches(comment.Value))
if (!variables.ContainsKey(variable.Groups["name"].Value))
variables.Add(variable.Groups["name"].Value, variable.Groups["value"].Value);
return variables;
}
Will first extract all the comments from the 'contents' string. Then it will extract all the variables it finds. It stores these in a dictionary and returns it to the caller.
i.e:
string contents = "some other HTML, lalalala <!-- variable1: \"wer2345235\" variable2: \"sdfgh333\" variable3: \"sdfsdfdfsdf\" --> foobarfoobarfoobar";
var variables = ParseCommentVariables(contents);
string variable1 = variables["variable1"];
string variable2 = variables["variable2"];