def extract_indices_from_range_str(filter_string, max_index=None):
    """
    Extract indices (e.g. for spectra or pixels) from a range string. The
    string must have the following format: Separate different ranges by ';',
    first index is 1.

    If max_index is provided, open ranges are allowed, as well as "-1" for all.

    Examples:
        "1;2;4;5"
        "2-10"
        "5-"
        "-1"

    Parameters
    ----------
    filter_string : string to be parsed according to the format specifications
    ¦   ¦   ¦   ¦   above
    max_index : (default: None). Provide the maximum index for the ranges to
    ¦   ¦   ¦   allow open ranges and "-1" for all indices
    """
    if filter_string is None:
        return None
    sections = filter_string.split(';')
    filter_ids = []
    for section in sections:
        filter_range = section.split('-')
        if len(filter_range) == 2:
            start = filter_range[0]
            end = filter_range[1]
            if end == '':
                if max_index is not None:
                    end = max_index
                else:
                    continue
            filter_ids += list(range(int(start) - 1, int(end)))
        else:
            filter_ids.append(int(section) - 1)
    return filter_ids
