import re


def extract_version_tag_from_url(url):
    """Extract a DataONE API version tag from a MN or CN service endpoint URL.

    Args:
      url : str
        Service endpoint URL. E.g.: ``https://mn.example.org/path/v2/object/pid``.

    Returns:
      str : Valid version tags are currently ``v1`` or ``v2``.

    """
    m = re.match(r"(/|^)(v\d)(/|$)", url)
    if not m:
        return None
    return m.group(2)