0

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?

1
  • This tool helped me a lot check it out debuggex.com Commented Mar 13, 2014 at 18:04

2 Answers 2

2

Easiest solution:

\(HOST=(.*?)\)

For example:

enter image description here

So in C#:

Match match = Regex.Match(inputString,@"\(HOST=(.*?)\)",RegexOptions.IgnoreCase | RegexOptions.Singleline);
string host_value = match.Groups[1].Value;
Sign up to request clarification or add additional context in comments.

1 Comment

That is exactly what I need. Do appreciate it!
0

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]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.