-1

我有这个文字

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

我想在上面的字符串中获取包含子字符串And或最接近(从左侧或右侧)Or包裹的字符串,其中是一个数字。( )W/digitdigit

在上面的例子中,我应该得到(测试或最佳)(苹果或 10a)

4

1 回答 1

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();
} 
于 2012-08-28T02:52:09.743 回答