import re


def wildcard_translate(pattern):
    """Translate a wildcard PATTERN to a regular expression object.

    This is largely inspired by fnmatch.translate.
    """

    i, n = 0, len(pattern)
    res = ''
    while i < n:
        char = pattern[i]
        i += 1
        if char == '*':
            res += '.*'
        else:
            res += re.escape(char)
    return re.compile(res + '\Z(?ms)')