import re


def sub_repeatedly(pattern, repl, term):
    """apply sub() repeatedly until no change"""
    while True:
        new_term = re.sub(pattern, repl, term)
        if new_term == term:
            return term
        term = new_term