import zipfile
import re


def load_zip_file_keys(file, file_name_reg_exp=''):
    """
    Returns an array with the entries of the ZIP file that match with
    the regular expression.
    The key's are the names or the file or the capturing group definied
    in the file_name_reg_exp
    """
    try:
        archive = zipfile.ZipFile(file, mode='r', allowZip64=True)
    except (RuntimeError, zipfile.BadZipFile):
        raise Exception('Error loading the ZIP archive.')

    pairs = []

    for name in archive.namelist():
        add_file = True
        key_name = name
        if file_name_reg_exp != "":
            m = re.match(file_name_reg_exp, name)
            if m is None:
                add_file = False
            else:
                if len(m.groups()) > 0:
                    key_name = m.group(1)

        if add_file:
            pairs.append(key_name)

    return pairs