2016-04-15 171 views
0

我有以下聲明:正則表達式匹配語句

(({ dbo.Document.MimeType_ID in (select ID from MimeType where Name ='PDF')} Or { dbo.WorkflowItem.CurrentStateName not like 'On_Hold%'}) And ({ dbo.DocumentMetaData.Field_ID=74 And dbo.DocumentMetaData.FieldValue Not like '%test%'} And { dbo.Document.FileName='karan'})) 

我想在4所陳述{}

dbo.Document.MimeType_ID in (select ID from MimeType where Name ='PDF') 
dbo.WorkflowItem.CurrentStateName not like 'On_Hold%' 
dbo.DocumentMetaData.Field_ID=74 And dbo.DocumentMetaData.FieldValue Not like '%test%' 
dbo.Document.FileName='karan' 
+2

是有嵌套模式?此外,我會建議你使用的解析器 – rock321987

+0

不,它不是嵌套模式,實際上是其前進的搜索公式,現在我要恢復搜索,我簡單的要求是如何得到{} –

+1

是https://regex101.com之間的所有語句/ r/tQ9bY6/2好? – rock321987

回答

1

此正則表達式就可以了(如果沒有嵌套模式)

\{\s*([^}]+)\s*\} 

C#代碼

string input = "(({ dbo.Document.MimeType_ID in (select ID from MimeType where Name ='PDF')} Or { dbo.WorkflowItem.CurrentStateName not like 'On_Hold%'}) And ({ dbo.DocumentMetaData.Field_ID=74 And dbo.DocumentMetaData.FieldValue Not like '%test%'} And { dbo.Document.FileName='karan'}))"; 
string pattern = "\\{\\s*([^}]+)\\s*\\}"; 
Regex rgx = new Regex(pattern); 

Match match = rgx.Match(input); 

while (match.Success) 
{ 
    Console.WriteLine(match.Groups[1].Value); 
    match = match.NextMatch(); 
} 

Ideone Demo