import re
import click


def extract_arxiv_id(link):
    """Extract arXiv ID from the given resource."""
    p = re.compile(r"http(?:s|)://arxiv.org/(?:abs/(.+\d)$|pdf/(.+\d)\.pdf$)")
    m = p.fullmatch(link)
    if m is not None:
        arxiv_id = m.group(1) if m.group(1) is not None else m.group(2)
    else:
        raise click.ClickException(f"Not a valid arXiv link: '{link}'.")
    return arxiv_id