import re


def _sort_names(names):
    """
    Sort peeker names by index and alphabetically.

    For example, the peeker names would be sorted as a[0], b[0], a[1], b[1], ...
    """

    def index_key(lbl):
        """Index sorting."""
        m = re.match(".*\[(\d+)\]$", lbl)  # Get the bracketed index.
        if m:
            return int(m.group(1))  # Return the index as an integer.
        return -1  # No index found so it comes before everything else.

    def name_key(lbl):
        """Name sorting."""
        m = re.match("^([^\[]+)", lbl)  # Get name preceding bracketed index.
        if m:
            return m.group(1)  # Return name.
        return ""  # No name found.

    srt_names = sorted(names, key=name_key)
    srt_names = sorted(srt_names, key=index_key)
    return srt_names