首页 > 代码库 > 正则随记

正则随记

string sql = "<add name=\"ZhiNuoDBEntities\" connectionString=\"metadata=res://*/Models.ZhiNuoDB.csdl|res://*/Models.ZhiNuoDB.ssdl|res://*/Models.ZhiNuoDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.1.105,7278;initial catalog=ZhiNuoDB;user id=sa;password=honnet;multipleactiveresultsets=True;App=EntityFramework&quot;\" providerName=\"System.Data.EntityClient\" />";
Regex rReg = new Regex(@"&quot;[\s\S]*?&quot;", RegexOptions.IgnoreCase);
string pContent = rReg.Match(sql).Value;

 

string sql = "metadata=res://*/Models.ZhiNuoDB.csdl|res://*/Models.ZhiNuoDB.ssdl|res://*/Models.ZhiNuoDB.msl;provider=System.Data.SqlClient;provider connection string=\"data source=192.168.1.105,7278;initial catalog=ZhiNuoDB;user id=sa;password=honnet;multipleactiveresultsets=True;App=EntityFramework";
Regex rReg = new Regex("data source[\\s\\S]*?True", RegexOptions.IgnoreCase);
string pContent = rReg.Match(sql).Value;

正则随记