-1

I have this text

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

I want to get the string(s) containing the substring And or Or wrapped in ( ) nearest to W/digit (from the left or right) in the above string, where digit is a number.

In the above example I should get (test or best) (apple OR 10a)

kaveman
  • 4,339
  • 25
  • 44

1 Answers1

0

try that:

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();
} 
TheHe
  • 2,933
  • 18
  • 22