// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace E { public class Program { private static readonly Regex re = new Regex(@"\s*([^=;]+?)\s*=\s*(([^';]+)|('[^']*'))", RegexOptions.Compiled); public static Dictionary SpecialParse(string s) { Dictionary res = new Dictionary(); foreach(Match m in re.Matches(s)) { res.Add(m.Groups[1].Value, m.Groups[2].Value); } return res; } public static void Main(string[] args) { string s = @"Provider=System.Data.SqlClient; Metadata=c:\metadata|c:\Metadata\Sql; Provider Connection String='Data Source=localhost; Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60'"; Dictionary d = SpecialParse(s); foreach(KeyValuePair kvp in d) { Console.WriteLine(kvp.Key + " : " + kvp.Value); } } } }