title: C# regex for negated character class unless chars are next to one another
body: <p>I need to match the characters between the innermost set of parentheses in a string, but allowing empty parens such as '()'. As best I can tell some kind of negative lookahead is needed here (and it is completely different than the question for which it is marked as duplicate)</p>
  
  <p>An initial version, which does <em>not</em> properly include '()' is:</p>
  
  <pre><code>var re = new Regex(@"\(([^()]+)\)");
  </code></pre>
  
  <p>Some test examples:</p>
  
  <pre><code>x (a) y          -&gt; a
  x (a b) y        -&gt; a b
  x (a b c) y      -&gt; a b c
  x (a b() c) y    -&gt; a b() c
  x (a() b() c) y  -&gt; a() b() c
  x (a b() c()) y  -&gt; a b() c()
  x (a b(a) c) y   -&gt; a
  x (a (b() c)) y  -&gt; b() c
  x () y           -&gt; empty
  </code></pre>
  
  <p>&nbsp;</p>
  
  <p>And a c# test method (adapt for your assertion library):</p>
  
  <pre class="lang-cs prettyprint-override"><code>var re = new Regex(@"\(([^()]+)\)");
  
  string[] tests = {
      "x (a) y", "a",
      "x (a b) y", "a b",
      "x (a b c) y", "a b c",
      "x (a b() c) y", "a b() c",
      "x (a() b() c) y", "a() b() c",
      "x (a b() c()) y", "a b() c()",
      "x (a b(a) c) y", "a",
      "x (a (b() c)) y", "b() c",
      "x () y", ""
  };
  
  for (int i = 0; i &lt; tests.Length; i+=2)
  {
      var match = re.Match(tests[i]);
      var result = match.Groups[1].Value;
      Assert.That(result, Is.EqualTo(tests[i + 1]));
  }
  </code></pre>