using System; using System.Text.RegularExpressions; using System.Collections.Generic; public class Test { public static void Main() { Dictionary configuracoes = new Dictionary(); string re = "([^\\s].*?)=([^;]+?)(;|$)"; string input = "Data Source=.\\SQLEXPRESS;Initial Catalog=Target_Database;User Id=User; Password=MyPassword"; foreach (Match m in Regex.Matches(input, re)) { //Exibe os resultados encontrados, pode remover isto é só para testes //Console.WriteLine("Chave: {0} - Valor: {1}", m.Groups[1].Value, m.Groups[2].Value); //Salva o item configuracoes[m.Groups[1].Value] = m.Groups[2].Value; } Console.WriteLine("Valor: {0}", configuracoes["Data Source"]); // Retorna .\SQLEXPRESS Console.WriteLine("Valor: {0}", configuracoes["Initial Catalog"]); // Retorna Target_Database Console.WriteLine("Valor: {0}", configuracoes["User Id"]); // Retorna User Console.WriteLine("Valor: {0}", configuracoes["Password"]); // Retorna MyPassword } }