title: How to capture parentheses only when escaped?
body: <p>I'm defining a regex as follows:</p>
  
  <pre><code>regex = new Regex(@"^\(([^()]+)\)", RegexOptions.Multiline);
  </code></pre>
  
  <p>This has been useful for processing content like this:</p>
  
  <pre><code>abc
  123
  (xyz)
  some things
  (more of the other)
  </code></pre>
  
  <p>and returning group 1 matches for:</p>
  
  <pre><code>xyz
  more of the other
  </code></pre>
  
  <p>However, when it encounters text like this:</p>
  
  <pre><code>abc
  123
  (xyz)
  some things
  (111 \(look at this\) 999)
  (more of the other)
  </code></pre>
  
  <p>I want it to match</p>
  
  <pre><code>xyz
  111 \(look at this\) 999
  more of the other
  </code></pre>
  
  <p>But I can't figure out how to modify the character class <code>[^()]</code> to indicate that parentheses are acceptable when escaped with a preceding "\".  I tried:</p>
  
  <pre><code>^\((([^()]|\\\(|\\\))+)\)
  </code></pre>
  
  <p>But the group 1 matches for this are:</p>
  
  <pre><code>xyz
  111 \(look at this\
  more of the other
  </code></pre>
  
  <p>Note the missing closing parenthesis in the second match.</p>
  
  <p>EDIT: I forgot to mention that there can be text following a parenthesis group, which should not be captured, e.g.:</p>
  
  <pre><code>(more of the other) TB ff
  </code></pre>
  
  <p>should only capture</p>
  
  <pre><code>more of the other
  </code></pre>