def _GetTextInside(text, start_pattern):
 matching_punctuation = {'(': ')', '{': '}', '[': ']'}
 closing_punctuation = set(itervalues(matching_punctuation))
 match = re.search(start_pattern, text, re.M)
 if (not match):
  return None
 start_position = match.end(0)
 assert (start_position > 0), 'start_pattern must ends with an opening punctuation.'
 assert (text[(start_position - 1)] in matching_punctuation), 'start_pattern must ends with an opening punctuation.'
 punctuation_stack = [matching_punctuation[text[(start_position - 1)]]]
 position = start_position
 while (punctuation_stack and (position < len(text))):
  if (text[position] == punctuation_stack[(-1)]):
   punctuation_stack.pop()
  elif (text[position] in closing_punctuation):
   return None
  elif (text[position] in matching_punctuation):
   punctuation_stack.append(matching_punctuation[text[position]])
  position += 1
 if punctuation_stack:
  return None
 return text[start_position:(position - 1)]

def _GetTextInside ( text , start_pattern ) : matching_punctuation = { '(' : ')' , '{' : '}' , '[' : ']' } closing_punctuation = set ( itervalues ( matching_punctuation ) ) match = re . search ( start_pattern , text , re . M ) if ( not match ) : return None start_position = match . end ( 0 ) assert ( start_position > 0 ) , 'start_pattern must ends with an opening punctuation.' assert ( text [ ( start_position - 1 ) ] in matching_punctuation ) , 'start_pattern must ends with an opening punctuation.' punctuation_stack = [ matching_punctuation [ text [ ( start_position - 1 ) ] ] ] position = start_position while ( punctuation_stack and ( position < len ( text ) ) ) : if ( text [ position ] == punctuation_stack [ ( - 1 ) ] ) : punctuation_stack . pop ( ) elif ( text [ position ] in closing_punctuation ) : return None elif ( text [ position ] in matching_punctuation ) : punctuation_stack . append ( matching_punctuation [ text [ position ] ] ) position += 1 if punctuation_stack : return None return text [ start_position : ( position - 1 ) ]
retrieves all the text between matching open and close parentheses .