import re


def process_ref(paper_id):
    """Attempt to extract arxiv id from a string"""

    # if user entered a whole url, extract only the arxiv id part
    paper_id = re.sub("https?://arxiv\.org/(abs|pdf|ps)/", "", paper_id)
    paper_id = re.sub("\.pdf$", "", paper_id)

    # strip version
    paper_id = re.sub("v[0-9]+$", "", paper_id)

    # remove leading arxiv, i.e., such that paper_id='    arXiv: 2001.1234' is still valid
    paper_id = re.sub("^\s*arxiv[:\- ]", "", paper_id, flags=re.IGNORECASE)

    return paper_id