[Mono-list] Regex Help..

Yves Kurz ml_yves@magnific.ch
Sat, 25 Sep 2004 11:23:31 +0200


I have to parse a string like
yyy.xxx.zzz:key1=val1,key2=val2,key3=val3...  where the number of
key/value pairs is not specified, the value of a key can be an empty or
a quoted string like "some\"\nvalue". The first part is the domain.
Now i would like to get each part separated, the domain and each
key/value pair. 

I have been trying something like:

string str = "ch.hta-bi.bfh.ch:key1=value2,key2=value3";

Regex rx = new Regex (@"^(?<domain>[^:]*):(?<key>[^=]+)=(?

MatchCollection matches = rx.Matches (str);

foreach (Match m in matches) {
	int i = 0;
	if (m.Length != 0)
		Console.WriteLine (i++ +": "+m.Groups["domain"] + " " + m.Groups
["key"] + " " + m.Groups["value"]);

This works not correct. This way I get just the last key value pair. 
What i'm doing wrong here? Is it possible at all to do with a regex?