日期:2014-05-18 浏览次数:20806 次
using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string str = "Data Source='192.168.0.4';database='mdb';uid='sa';pwd='sa';"; Regex reg = new Regex(@"^Data Source='(?<datasource>.*?[^;])';database='(?<database>.*?[^;])';uid='(?<uid>.*?[^;])';pwd='(?<pwd>.*?[^;])';$", RegexOptions.IgnoreCase); Match m=reg.Match(str); if (m.Success) { Console.WriteLine(m.Groups["datasource"].Value);//192.168.0.4 Console.WriteLine(m.Groups["database"].Value);//mdb Console.WriteLine(m.Groups["uid"].Value);//sa Console.WriteLine(m.Groups["pwd"].Value);//sa } Console.Read(); } } }