r""" Clean up urlpattern regexes into something more readable by humans. For example, turn "^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$" into "/<sport_slug>/athletes/<athlete_slug>/".
(pattern)
| 509 | |
| 510 | |
| 511 | def simplify_regex(pattern): |
| 512 | r""" |
| 513 | Clean up urlpattern regexes into something more readable by humans. For |
| 514 | example, turn "^(?P<sport_slug>\w+)/athletes/(?P<athlete_slug>\w+)/$" |
| 515 | into "/<sport_slug>/athletes/<athlete_slug>/". |
| 516 | """ |
| 517 | pattern = remove_non_capturing_groups(pattern) |
| 518 | pattern = replace_named_groups(pattern) |
| 519 | pattern = replace_unnamed_groups(pattern) |
| 520 | pattern = replace_metacharacters(pattern) |
| 521 | if not pattern.startswith("/"): |
| 522 | pattern = "/" + pattern |
| 523 | return pattern |