def matchBrackets(string):
 rest = string[1:]
 inside = u'('
 while ((rest != u'') and (not rest.startswith(u')'))):
  if rest.startswith(u'('):
   (part, rest) = matchBrackets(rest)
   inside = (inside + part)
  else:
   inside = (inside + rest[0])
   rest = rest[1:]
 if rest.startswith(u')'):
  return ((inside + u')'), rest[1:])
 raise AssertionError(((u"Unmatched bracket in string '" + string) + u"'"))

def matchBrackets ( string ) : rest = string [ 1 : ] inside = u'(' while ( ( rest != u'' ) and ( not rest . startswith ( u')' ) ) ) : if rest . startswith ( u'(' ) : ( part , rest ) = matchBrackets ( rest ) inside = ( inside + part ) else : inside = ( inside + rest [ 0 ] ) rest = rest [ 1 : ] if rest . startswith ( u')' ) : return ( ( inside + u')' ) , rest [ 1 : ] ) raise AssertionError ( ( ( u"Unmatched bracket in string '" + string ) + u"'" ) )
separate the contents matching the first set of brackets from the rest of the input .