In this code below I’d like to return this string suing regex: ‘DataSource=xxxtransxxx;Initial Catalog=Sales‘
Sales could or could not have a prefix and there could or could not be spaces in between the items in the string above. I have tried the regex in the code below but it does not work. Any advice appreciated, thanks!!
var thestring = @"'SELECT CONVERT(VARCHAR(MAX), [Measures].[EmployeeID ParameterCaption]) AS [EmployeeID]
,CONVERT(VARCHAR(50), [Measures].[Sales Rep Name ParameterCaption]) AS [EmployeeName]
,CONVERT(VARCHAR(50), [Measures].[Manager EmployeeID ParameterCaption]) AS [ManagerEmployeeID]
,CONVERT(MONEY, [MEASURES].[PrevFYYTD])AS PrevFYYTD
,CONVERT(MONEY, [MEASURES].[CurrentFYYTD] ) AS CurrentFYYTD
,CONVERT(VARCHAR(50),[MEASURES].[PCTGrowth] )+''%'' AS [PCTGrowth]
,CONVERT(VARCHAR, [MEASURES].[DollarGrowth] ) AS DollarGrowth
,CONVERT(VARCHAR, [MEASURES].[HasParent] ) AS HasParent
,CONVERT(VARCHAR, [MEASURES].[HasChild] ) AS HasChild
FROM OPENROWSET(''MSOLAP'',''DataSource=xxxtransxxx;Initial Catalog=Sales'' , SET @MDX = ''' WITH;";
Regex rgx = new Regex(@"'\s*DataSource\s*=\s.*trans*(.*Sales) *'", RegexOptions.IgnoreCase);
string result = rgx.Match(thestring).Groups[0].Value;
You could use
code
explanation