import re


def expand_subject_ids(subject_id):
    """
    If the given subject ID represents a range of IDs, returns a list of all
    of them. For example:
    6.S193-6.S198 ==> [6.S193, 6.S194, 6.S195, 6.S196, 6.S197, 6.S198]
    10.81 (10.83, 10.85, 10.87) ==> [10.81, 10.83, 10.85, 10.87]
    """

    # Matches 6.S193-6.S198
    match = re.match(r'([A-Z0-9.]+[^0-9])([0-9]+)-[A-Z0-9.]+[^0-9]([0-9]+)', subject_id)
    if match is not None:
        base = match.group(1)
        start_num = int(match.group(2))
        end_num = int(match.group(3))
        return [base + str(num).zfill(len(match.group(2))) for num in range(start_num, end_num + 1)]

    # Matches 10.81 (10.83, 10.85, 10.87)
    match = re.match(r'([A-Z0-9.]+)\s*\(((?:[A-Z0-9.]+,\s*)*(?:[A-Z0-9.]+\s*))\)', subject_id)
    if match is not None:
        base = match.group(1)
        alternatives = match.group(2).split(',')
        return [base.strip()] + [alt.strip() for alt in alternatives]

    return [subject_id]