def check_label(labels, required, value_regex, target_labels):
    present = target_labels is not None and not set(labels).isdisjoint(set(target_labels))
    if present:
        if required and not value_regex:
            return True
        elif value_regex:
            pattern = re.compile(value_regex)
            present_labels = set(labels) & set(target_labels)
            for l in present_labels:
                if not bool(pattern.search(target_labels[l])):
                    return False
            return True
        else:
            return False
    else:
        return not required