title: Extract strings between brackets and nested brackets
body: <p>So I have a file of text and titles, (titles indicated with the starting &quot;;&quot;)</p>
  <pre><code>;star/stellar_(class(ification))_(chart)
  
  Hertz-sprussels classification of stars is shows us . . .
  </code></pre>
  <p>What I want to do is have it where it's split by &quot;_&quot; into
  <code>['star/stellar','(class(ification))','(chart)']</code>, interating through them and extracting whats in the brackets, e.g. <code>'(class(ification))'</code> to <code>{'class':'ification'}</code> and <code>(chart)</code> to just <code>['chart']</code>.
  All i've done so far is the splitting part</p>
  <pre><code>for ln in open(file,&quot;r&quot;).read().split(&quot;\n&quot;):
      if ln.startswith(&quot;;&quot;):
          keys=ln[1:].split(&quot;_&quot;)
  </code></pre>
  <p>I have ways to extract bits in brackets, but I have had trouble finding a way that supports nested brackets in order.
  I've tried things like <code>re.findall('\(([^)]+)',ln)</code> but that returns <code>['star/stellar', '(class', 'chart']</code>. Any ideas?</p>