Showing posts with label regex. Show all posts
Showing posts with label regex. Show all posts

Monday, December 14, 2009

Regular expressions for connection string parsing

Collection of regular expressions for parsing of connection string:
Split to parts:
string regexSplitToParts = "([^=;]*)=([^=;]*)";
RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled;
Regex reg = new Regex(regexSplitToParts, options);


Fetch specific part of connection string (e.g. DataSource):
string regexDataSource = "Data\\sSource(\\s)*=(\\s)*(?<DataSourceName>([^;]*))";
RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled;
Regex reg = new Regex(regexDataSource, options);

Technorati Tags: