Skip to content

Instantly share code, notes, and snippets.

Last active March 19, 2017 03:47
What would you like to do?
# borrow from
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: if len( % 2 else + '(?:', p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment