import re


def input_must_match_regex(regex, error_message):
    """
    The user must type an input that matches a regex. Return his input
    :param regex regex: Regular expression object
    :param str error_message: The error message that must be displayed
    :return: The user's valid answer
    :rtype: str
    """
    answer = None
    while answer is None:
        answer = input()
        if re.search(regex, answer) is None:
            answer = None
            print("Please try again:")
    return answer