import zipfile
import re


def load_zip_file_keys(file, fileNameRegExp=''):
    """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
    fileNameRegExp
    """
    try:
        archive = zipfile.ZipFile(file, mode='r', allowZip64=True)
    except:
        raise Exception('Error loading the ZIP archive.')

    pairs = []

    for name in archive.namelist():
        addFile = True
        keyName = name
        if fileNameRegExp != '':
            m = re.match(fileNameRegExp, name)
            if m == None:
                addFile = False
            else:
                if len(m.groups()) > 0:
                    keyName = m.group(1)

        if addFile:
            pairs.append(keyName)

    return pairs