import re


def parse_rule(line):
    """Parse rule about what child bags a parent bag can contain

    :returns: (parent, {color1: quantity, color2: quantity, ...}
    """
    parent, children_str = line.strip().split(" bags contain ")
    children = {}
    for child in children_str.split(", "):
        match = re.match(r"(?P<quantity>\d+) (?P<color>.+?) bag", child)
        if match:
            children[match.group("color")] = int(match.group("quantity"))
    return parent, children