Match a request with parameter to it's corresponding route

def match_route(self, reqpath):
        """Match a request with parameter to it's corresponding route"""
        route_dicts = [routes for _, routes in self.api.http.routes.items()][0]
        routes = [route for route, _ in route_dicts.items()]
        if reqpath not in routes:
            for route in routes:  # replace params in route with regex
                reqpath = re.sub('^(/v\d*/?)', '/', reqpath)
                base_url = getattr(self.api.http, 'base_url', '')
                reqpath = reqpath.replace(base_url, '', 1) if base_url else reqpath
                if re.match(re.sub(r'/{[^{}]+}', r'/[\\w-]+', route) + '$', reqpath):
                    return route

        return reqpath