Hey all I am in need of getting a regex so that i can parse a sql connection string out.
I am currently doing so with .Split() but that is proving to not be very reliable.
The connection string looks like this:
It gets messed up between the splits of ":" and ";" so this is why I would like to figure out a regex pattern so its much easier (and more reliable) than doing this .Split() stuff. I'm just not really good at regex!
What I am needing to get is the format:
And help would be great!
I am currently doing so with .Split() but that is proving to not be very reliable.
The connection string looks like this:
The .Split() code I am currently using is this (data being the connection string above):dbConnectionString=jdbc:sqlserver://theServerName:1433;database=theDBName;intergratedSecurity=true;encrypt=true;trustServerCertificate=true
C#:
string[] values = data.Split('=');
switch ((entry.Key.ToLower()))
{
case "dbconnectionstring":
string[] __values = data.Split(':');
string[] ___values = __values[3].Split(';');
txt_box1 = __value[0].ToLower().Replace("dbConnectionString", "") + ":" + __values[1].ToLower();
txt_box2 = __values[2].Replace("//", "");
txt_box3 = ___values[0];
break;
case "database":
txt_box4 = _values[1];
break;
case "encrypt":
txt_box5 = _values[1];
break;
case "trustServerCertificate":
txt_box6 = _values[1];
break;
}
It gets messed up between the splits of ":" and ";" so this is why I would like to figure out a regex pattern so its much easier (and more reliable) than doing this .Split() stuff. I'm just not really good at regex!
What I am needing to get is the format:
C#:
jdbc:sqlserver://
theServerName
1433
theDBName
true
true
true
And help would be great!