import re


def _subr(regex, sub, text):
    """
    Recursive replacement.
    """

    # make substitutions, get the number of substitutions "n"
    text, n = re.subn(regex, sub, text)

    # continue substituting
    if n:
        return _subr(regex, sub, text)

    return text