import re


def split_url_at_version_tag(url):
    """Split a DataONE REST API URL.

    Return: BaseURL, version tag, path + query E.g.:
    http://dataone.server.edu/dataone/mn/v1/objects/mypid ->
    'http://dataone.server.edu/dataone/mn/', 'v1', 'objects/mypid'

    """
    m = re.match(r"(.*?)(/|^)(v[123])(/|$)(.*)", url)
    if not m:
        raise ValueError('Unable to get version tag from URL. url="{}"'.format(url))
    return m.group(1), m.group(3), m.group(5)