def simplify_regex(pattern):
 pattern = named_group_matcher.sub((lambda m: m.group(1)), pattern)
 pattern = non_named_group_matcher.sub('<var>', pattern)
 pattern = pattern.replace('^', '').replace('$', '').replace('?', '').replace('//', '/').replace('\\', '')
 if (not pattern.startswith('/')):
  pattern = ('/' + pattern)
 return pattern

def simplify_regex ( pattern ) : pattern = named_group_matcher . sub ( ( lambda m : m . group ( 1 ) ) , pattern ) pattern = non_named_group_matcher . sub ( '<var>' , pattern ) pattern = pattern . replace ( '^' , '' ) . replace ( '$' , '' ) . replace ( '?' , '' ) . replace ( '//' , '/' ) . replace ( '\\' , '' ) if ( not pattern . startswith ( '/' ) ) : pattern = ( '/' + pattern ) return pattern
clean up urlpattern regexes into something more readable by humans .