Tags : c#connection stringregex
This regex snippet returns the database instance name, host name, and database name from a connection string.
using System.Text.RegularExpressions;
const string REGEX_CONNECTION_STRING_PATTERN
= @"=(?<sqlServerName>.+);Initial Catalog=(?<databaseName>\w+);";
static readonly Regex ConnectionString_Regex
= new Regex (REGEX_CONNECTION_STRING_PATTERN, RegexOptions.IgnoreCase);
static GroupCollection ParseConnectionString (string inputString)
{
Match match = ConnectionString_Regex.Match (inputString);
return match.Groups;
}
blog comments powered by Disqus