Reputation: 21
I have a connection string
"User ID=abc;Password=pwd;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=PRDREPTQ)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PRRQ)))"
I want to use regular expression to parse out the host "PRDREPTQ" value only. Can anybody help me write the pattern?
Upvotes: 0
Views: 2300
Reputation: 59232
Use this:
Regex HOST=(\w+)
And capture the first group
string testString = "User ID=abc;Password=pwd;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=PRDREPTQ)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PRRQ)))";
var match= Regex.Match(testString, @"HOST=(\w+)");
Console.WriteLine(match.Groups[1]);
Upvotes: 0
Reputation: 29668
Easiest solution:
\(HOST=(.*?)\)
For example:
So in C#:
Match match = Regex.Match(inputString,@"\(HOST=(.*?)\)",RegexOptions.IgnoreCase | RegexOptions.Singleline);
string host_value = match.Groups[1].Value;
Upvotes: 2