def _re_flatten(p):
 if ('(' not in p):
  return p
 return re.sub('(\\\\*)(\\(\\?P<[^>]+>|\\((?!\\?))', (lambda m: (m.group(0) if (len(m.group(1)) % 2) else (m.group(1) + '(?:'))), p)

def _re_flatten ( p ) : if ( '(' not in p ) : return p return re . sub ( '(\\\\*)(\\(\\?P<[^>]+>|\\((?!\\?))' , ( lambda m : ( m . group ( 0 ) if ( len ( m . group ( 1 ) ) % 2 ) else ( m . group ( 1 ) + '(?:' ) ) ) , p )
turn all capturing groups in a regular expression pattern into non-capturing groups .