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