MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / _re_flatten

Function _re_flatten

21-async/mojifinder/bottle.py:253–258  ·  view source on GitHub ↗

Turn all capturing groups in a regular expression pattern into non-capturing groups.

(p)

Source from the content-addressed store, hash-verified

251
252
253def _re_flatten(p):
254 ''' Turn all capturing groups in a regular expression pattern into
255 non-capturing groups. '''
256 if '(' not in p: return p
257 return re.sub(r'(\\*)(\(\?P<[^>]+>|\((?!\?))',
258 lambda m: m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:', p)
259
260
261class Router(object):

Callers 2

__init__Method · 0.85
addMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected