from re import compile


def check_regex(regex):
    """Generate a function to match the regex.
    The regex will be compiled to speed up."""
    regex = compile(regex)
    def _check_regex(text):
        result = regex.match(text)
        return result is not None
    return _check_regex