import re


def generate_contexts_from_regex(schema_url, regex_input):
    """ Creates the context URL for the given schema url based
    on given regex

    :param schema_url: a schema URL
    :type schema_url: str
    :param regex_input: keys are the regex to locate and value the replace value
    :type regex_input: dict
    :return: a context URL
    """
    try:
        context_url = schema_url

        for regex in regex_input.keys():
            context_url = re.sub(regex, regex_input[regex], context_url)

        return context_url
    except Exception:
        raise Exception("There is a problem with your input")