import re


def string_to_iterable(string):
    """convert a string into an iterable
    note: ranges are inclusive

    >>> string_to_iterable('0,3,5-10,15-30-3,40')
    [0,3,5,6,7,8,9,10,15,18,21,24,27,30,40]
    """
    if re.search("[^\d^,^-]", string) is not None:
        raise ValueError("Iterable string must contain only digits, commas, and dashes")
    it = []
    splits = [tuple(s.split("-")) for s in string.split(",")]
    for item in splits:
        if len(item) == 1:
            it.append(int(item[0]))
        elif len(item) == 2:
            it.extend(list(range(int(item[0]), int(item[1]) + 1)))
        elif len(item) == 3:
            it.extend(list(range(int(item[0]), int(item[1]) + 1, int(item[2]))))
        else:
            raise ValueError("Iterable string items must be of length <= 3")
    return sorted(list(set(it)))