+def url_prefix(mat):
+ """Extract the URL prefix from a regex match.
+
+ :param mat: A regex match object.
+ :returns: The URL prefix, defined as the text before the match in the
+ original string. Normalized to start with one leading slash and end with
+ zero.
+ """
+ return '/' + mat.string[:mat.start()].strip('/')
+
+
+def get_repo(backend, mat):
+ """Get a Repo instance for the given backend and URL regex match."""
+ return backend.open_repository(url_prefix(mat))
+
+