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)
| 250 | |
| 251 | |
| 252 | def 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 | |
| 267 | def strip_p_tags(value): |
no test coverage detected