human
Complete this python program:
def fake_paths_by_regex(pattern, exists=True):
assistant
#Here is the Python code you requested.

    """Usage:
    >>> with fake_paths_by_regex(\\.pdf$\):
    ...     assert os.path.exists(\my.pdf\) == True
    >>> with fake_paths_by_regex(\\.pdf$\, exists=False):
    ...     assert os.path.exists(\my.pdf\) == False
    """
    regex = re.compile(pattern)
    def check(path):
        if regex.search(path):
            return exists
        return None
    return fake_paths(check)