day19/puzzle1.py
def expand(rules, index):
    """Return a regex object to match against messages"""

    # Remove citation marks
    for idx in rules:
        rules[idx] = rules[idx].replace('"', '')

    # Search-and-replace all indexes until all decimal values are eliminated.
    rule = " " + rules[index] + " "
    pattern = re.compile(r"(\d+)")
    while m := pattern.search(rule):
        idx = m.group(1)
        rule = rule.replace(" "+idx+" ", " ( "+rules[idx]+" ) ")

    pattern = "^" + rule.replace(" ", "") + "$"
    return re.compile(pattern)
Return a regex object to match against messages
Return a regex object to match against messages
Return a regex object to match against messages
def expand(rules, index):
    for idx in rules:
        rules[idx] = rules[idx].replace('"', '')
    rule = " " + rules[index] + " "
    pattern = re.compile(r"(\d+)")
    while m := pattern.search(rule):
        idx = m.group(1)
        rule = rule.replace(" "+idx+" ", " ( "+rules[idx]+" ) ")
    pattern = "^" + rule.replace(" ", "") + "$"
    return re.compile(pattern)
def expand ( rules , index ) : for idx in rules : rules [ idx ] = rules [ idx ] . replace ( '"' , '' ) rule = " " + rules [ index ] + " " pattern = re . compile ( r"(\d+)" ) while m := pattern . search ( rule ) : idx = m . group ( 1 ) rule = rule . replace ( " " + idx + " " , " ( " + rules [ idx ] + " ) " ) pattern = "^" + rule . replace ( " " , "" ) + "$" return re . compile ( pattern )
Return a regex object to match against messages
Return a regex object to match against messages
"""Return a regex object to match against messages""" # Remove citation marks # Search-and-replace all indexes until all decimal values are eliminated.
rules
index