Remove the outermost parens, keep the (?P...) one

    >>> unpack(r'(abc)')
    'abc'
    >>> unpack(r'(?:abc)')
    'abc'
    >>> unpack(r'(?P<xyz>abc)')
    '(?P<xyz>abc)'
    >>> unpack(r'[abc]')
    '[abc]'

def unpack(regex):
    """
    Remove the outermost parens, keep the (?P...) one

    >>> unpack(r'(abc)')
    'abc'
    >>> unpack(r'(?:abc)')
    'abc'
    >>> unpack(r'(?P<xyz>abc)')
    '(?P<xyz>abc)'
    >>> unpack(r'[abc]')
    '[abc]'
    """
    if is_packed(regex) and not regex.startswith('(?P<'):
        return re.sub(r'^\((\?:)?(?P<content>.*?)\)$', r'\g<content>', regex)
    else:
        return regex