MCPcopy
hub / github.com/django/django / remove_non_capturing_groups

Function remove_non_capturing_groups

django/contrib/admindocs/utils.py:252–264  ·  view source on GitHub ↗

r""" Find non-capturing groups in the given `pattern` and remove them, e.g. 1. (?P<a>\w+)/b/(?:\w+)c(?:\w+) => (?P<a>\\w+)/b/c 2. ^(?:\w+(?:\w+))a => ^a 3. ^a(?:\w+)/b(?:\w+) => ^a/b

(pattern)

Source from the content-addressed store, hash-verified

250
251
252def remove_non_capturing_groups(pattern):
253 r"""
254 Find non-capturing groups in the given `pattern` and remove them, e.g.
255 1. (?P<a>\w+)/b/(?:\w+)c(?:\w+) => (?P<a>\\w+)/b/c
256 2. ^(?:\w+(?:\w+))a => ^a
257 3. ^a(?:\w+)/b(?:\w+) => ^a/b
258 """
259 group_start_end_indices = _find_groups(pattern, non_capturing_group_matcher)
260 final_pattern, prev_end = "", None
261 for start, end, _ in group_start_end_indices:
262 final_pattern += pattern[prev_end:start]
263 prev_end = end
264 return final_pattern + pattern[prev_end:]
265
266
267def strip_p_tags(value):

Callers 1

simplify_regexFunction · 0.90

Calls 1

_find_groupsFunction · 0.85

Tested by

no test coverage detected