def filterMapNames(regexText,  records=getIndex(), excludeRegex=False, closestMatch=True):
bestScr = <NUM_LIT> <EOL>regex = re.compile(regexText, flags=re.IGNORECASE)<EOL>ret = []<EOL>if excludeRegex: <EOL><INDENT>if regexText and closestMatch: <EOL><INDENT>for m in list(records):<EOL><INDENT>if re.search(regex, m.name): continue <EOL>score = len(m.name) <EOL>if score == bestScr:<EOL><INDENT>bestScr = score<EOL>ret.append(m)<EOL><DEDENT>elif score <  bestScr: <EOL><INDENT>bestScr = score<EOL>ret = [m]<EOL><DEDENT><DEDENT><DEDENT>else: <EOL><INDENT>for m in list(records):<EOL><INDENT>if re.search(regex, m.name): continue <EOL>ret.append(m) <EOL><DEDENT><DEDENT><DEDENT>else: <EOL><INDENT>if regexText and closestMatch: <EOL><INDENT>for m in records:<EOL><INDENT>if not re.search(regex, m.name): continue <EOL>score = len(m.name) <EOL>if score == bestScr:<EOL><INDENT>bestScr = score<EOL>ret.append(m)<EOL><DEDENT>elif score <  bestScr: <EOL><INDENT>bestScr = score<EOL>ret = [m]<EOL><DEDENT><DEDENT><DEDENT>else: <EOL><INDENT>for m in records:<EOL><INDENT>if not re.search(regex, m.name): continue <EOL>ret.append(m) <EOL><DEDENT><DEDENT><DEDENT>return ret<EOL>
matches each record against regexText according to parameters
    NOTE: the code could be written more simply, but this is loop-optimized to
          scale better with a large number of map records