import re


def remove_markdown(text):
    """
    Removes markdown formatting from the input text.

    :param text: the text to cleanup
    :return: the cleaned up text.
    """

    # Strip URLs
    text = re.sub(r"\[([^]]+)\][ ]?\(([^)]+)\)", r"\g<1>", text)

    # Remove star-marked bold and italic
    # We apply the regex three times to remove
    # *italic*, **bold**, ***bold and italic***
    text = re.sub(r"\*([^]]+)\*", r"\g<1>", text)
    text = re.sub(r"\*([^]]+)\*", r"\g<1>", text)
    text = re.sub(r"\*([^]]+)\*", r"\g<1>", text)

    # Remove underline-marked bold and italic
    text = re.sub(r"_([^]]+)_", r"\g<1>", text)
    text = re.sub(r"_([^]]+)_", r"\g<1>", text)
    text = re.sub(r"_([^]]+)_", r"\g<1>", text)

    # Remove code
    text = re.sub(r"`([^]]+)`", r"\g<1>", text)

    # Remove strikethrough
    text = re.sub(r"~~([^]]+)~~", r"\g<1>", text)

    # Remove spoilers
    text = re.sub(r">!([^]]+)!<", r"\g<1>", text)

    return text