<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def delete(path, regex=None, recurse=False, test=False):
 """Deletes the file or directory at `path`. If `path` is a directory and `regex` is provided, matching files will be deleted; `recurse` controls whether subdirectories are recursed. A list of deleted items is returned. If `test` is true, nothing will be deleted and a list of items that would have been deleted is returned. """

    deleted = []
    if op.isfile(path):
        if not test: os.remove(path)
        else: return [path]
        return [] if op.exists(path) else [path]
    elif op.isdir(path):
        if regex:
            for r,ds,fs in os.walk(path):
                for i in fs:
                    if _is_match(regex, i):
                        deleted += delete(op.join(r,i), test=test)
                if not recurse:
                    break
        else:
            if not test: shutil.rmtree(path)
            else: return [path]
            return [] if op.exists(path) else [path]
    return deleted