在下面的这段代码中,我想用正则表达式返回这个字符串:' DataSource=xxxtransxxx;Initial Catalog=Sales
'
Sales
可以或不能有 aprefix
并且在上面的字符串中的项目之间可以或不可以有空格。我在下面的代码中尝试了正则表达式,但它不起作用。任何建议表示赞赏,谢谢!
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;