M
Martin Hart
I have a connection string that I would like to extract a part from, but
my knowledge does not extend far enough to resolve my problem.
I can have strings like:
"Integrated Security=SSPI;Persist Security Info=False;Initial
Catalog=GestionNet00001;Data Source=localhost;MultipleActiveResultSets=true"
or
"Integrated Security=SSPI;Persist Security Info=False;Initial
Catalog=GestionNet00001;Data Source=localhost"
I want to extract the "localhost" part of the string when (and only
when) it is preceded with "Data Source=". I have devised a regular
expression like this: "(?<=Data\s+Source\s*=)(.*)(?=[;\n\r$])".
This works fine for the first string as the "localhost" is suffixed with
a colon, but in the case of the second string it does not have a suffix,
and fails.
My Regex constructor look like this:
Regex regex = new Regex(@"(?<=Data\s+Source\s*=)(.*)(?=[;\n\r$])",
RegexOptions.IgnoreCase |
RegexOptions.CultureInvariant |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Compiled
);
Can anyone help me with this problem?
TIA,
MartinH.
my knowledge does not extend far enough to resolve my problem.
I can have strings like:
"Integrated Security=SSPI;Persist Security Info=False;Initial
Catalog=GestionNet00001;Data Source=localhost;MultipleActiveResultSets=true"
or
"Integrated Security=SSPI;Persist Security Info=False;Initial
Catalog=GestionNet00001;Data Source=localhost"
I want to extract the "localhost" part of the string when (and only
when) it is preceded with "Data Source=". I have devised a regular
expression like this: "(?<=Data\s+Source\s*=)(.*)(?=[;\n\r$])".
This works fine for the first string as the "localhost" is suffixed with
a colon, but in the case of the second string it does not have a suffix,
and fails.
My Regex constructor look like this:
Regex regex = new Regex(@"(?<=Data\s+Source\s*=)(.*)(?=[;\n\r$])",
RegexOptions.IgnoreCase |
RegexOptions.CultureInvariant |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Compiled
);
Can anyone help me with this problem?
TIA,
MartinH.