import re


def format_companies(company):
    """
    Format the selected company so that the API can find relevant articles.
    """
    # Remove junk at the end of the names
    if company[-6:] == ", Inc.":
        return re.sub(r' ', "-", company[:-6])

    if company[-5:] == ", Inc":
        return re.sub(r' ', "-", company[:-5])

    if company[-5:] == " Inc.":
        return re.sub(r' ', "-", company[:-5])

    return re.sub(r' ', "-", company)