What would be the Regex to grab the innermost set of parentheses containing a specific character; '|' in this case?
Some examples and a (c#) test method:
string[] tests = {
"x () y", "",
"x (a) y", "",
"x (a.b()) y", "",
"x ((a).b() | (b).c()) y", "(a).b() | (b).c()",
"x (a|b) y", "a|b",
"x ((a|b) | c)", "a|b",
"x (a|b|c) y", "a|b|c",
"x (a|a.b()|c) y", "a|a.b()|c",
"x (a.b()|b.c()) y", "a.b()|b.c()",
"x (a.b()|b.c()|c) y", "a.b()|b.c()|c",
"x (a|b.c()|c.d()) y", "a|b.c()|c.d()",
"x (a|(b.c()|d)) y", "b.c()|d",
"x (a|a.b(a)|c) y", "a|a.b(a)|c"
};
for (int i = 0; i < tests.Length; i+=2)
{
var match = re.Match(tests[i]);
var result = match.Groups[1].Value;
Assert.That(result, Is.EqualTo(tests[i + 1]));
}