2012-08-28 56 views
-1

我有這樣的文字正則表達式最近字匹配貪婪

"(Objectid < 200 OR ObjectID > 600) and (test or best) W/5 AND (apple OR 10a) AND (Objectid < 100 OR ObjectID > 500)" 

我想包含包裹在()最接近W/digit子串AndOr字符串(S)在上述(從左側或右側)字符串,其中digit是一個數字。

在上面的例子中,我應該得到(測試或最佳)(蘋果或10A)

回答

0

嘗試:

var rgx = new Regex(@"(\([^)]*\))\WW/\d+\W(?:AND|OR|IN)\W(\([^)]*\))", RegexOptions.IgnoreCase); 
var items = new List<Tuple<string,string>>(); 
var match = rgx.Match(subjectString); 
while (match.Success) { 
    items.Add(new Tuple<string,string>(match.Groups[1].Value, match.Groups[2].Value)); 
    match = match.NextMatch(); 
}