title: Using python regex to change variations of a string?
body: <p>I have a list of strings that follow this general pattern:</p>
  
  <pre><code>X (a, b, c, d)
  </code></pre>
  
  <p>where:</p>
  
  <p><code>X</code> is some variation of the string <code>item description</code></p>
  
  <p><code>a, b, c, d</code> is some variation of comma separated words, symbols, numbers.</p>
  
  <p>I'm trying to remove the parenthesis and text outside the parenthesis so that it becomes this:</p>
  
  <pre><code>a, b, c, d
  </code></pre>
  
  <p>I have noticed some horrendous variations on the input:</p>
  
  <pre><code># ideal input
  items (lcd, cardboard, hats on rack, keyboard cat)
  
  # Sometimes missing/extra space (both outside text and inside)
  items( lcd , cardboard,hats on rack  , keyboard cat)
  
  # Outside text may contain other symbols and words
  items &amp; descrips: (lcd, cardboard, hats on rack, keyboard cat)
  
  # Inner text may contain parenthesis, brackets, other enclosures
  descriptions &amp; items: (lcd (for computer), cardboard  {brown &amp; white colored}, hats on rack, keyboard cat[dept. 11])
  
  # Parent parenthesis may not be closed
  items: (lcd, cardboard, hats on rack, keyboard cat (dept. 11)
  
  # Using semi-colons instead of commas
  item (lcd; cardboard; hats on rack; keyboard cat)
  
  # Some text have non-ascii characters
  item (lcd\u2122, cardboard)
  </code></pre>
  
  <p><strong>The ideal output would be</strong></p>
  
  <pre><code>lcd, cardboard, hats on rack, keyboard cat
  </code></pre>
  
  <p>Some clarifications:</p>
  
  <p>(1) Any inner enclosures (and its data) should be removed</p>
  
  <p>ie: </p>
  
  <pre><code>descriptions &amp; items: (lcd (for computer), cardboard  {brown &amp; white colored}, hats on rack, keyboard cat[dept. 11])
  </code></pre>
  
  <p>should be:</p>
  
  <pre><code>lcd, cardbard, hats on rack, keyboard cat
  </code></pre>
  
  <p>What's an appropriate regex for this? The different variations make this very difficult with my limited regex skills.</p>
  
  <p>Sample input array:</p>
  
  <pre><code>a = [
  "items (lcd, cardboard, hats on rack, keyboard cat)",
  "items( lcd , cardboard,hats on rack  , keyboard cat)",
  "items &amp; descrips: (lcd, cardboard, hats on rack, keyboard cat)",
  "descriptions &amp; items: (lcd (for computer), cardboard  {brown &amp; white colored}, hats on rack, keyboard cat[dept. 11])",
  "items: (lcd, cardboard, hats on rack, keyboard cat (dept. 11)",
  "items: (lcd, cardboard, hats on rack, keyboard cat [dept. 11]",
  "item (lcd; cardboard; hats on rack; keyboard cat)", 
  u"item (lcd\u2122, cardboard)"
  ]
  </code></pre>