fyi: how you could do this using Linq to produce a Dictionary<string, List<string>>:
char[] splitchar1 = new[] {'.'};
char[] splitchar2 = new[] {':'};
char[] splitchar3 = new[] {','};
string text = "animal: leather, bacon, eagle. vegetable: timber, potato. mineral: granite, gem stones, waterfall.";
private void SomeButton_Click(object sender, EventArgs e)
{
Dictionary<string, List<string>> test = ParseText(text);
}
private Dictionary<string,>> ParseText(string text)
{
return text.Split(splitchar1, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Split(splitchar2, StringSplitOptions.RemoveEmptyEntries))
.ToDictionary(
key => key[0],
val => val[1].Split(splitchar3,StringSplitOptions.RemoveEmptyEntries).ToList());
}
Some of us, are, you might say, RegEx "challenged." But, I do think RegEx is a very good thing, and wish that I once had a reason (back when) to have studied it in depth. While it's my opinion that it's better, in early development, to break-code-out into fuller form than RegEx, and then, in later development, optimize with RegEx in places you identify it can be much more performant, many people I respect do not share that opinion.
You could make a valid argument, I think, that, for someone who doesn't know Linq, that the Linq shown here is as "opaque" as RegEx is to someone who doesn't know RegEx :)