def rreplace(s, old, new, occurrence):
    """This function performs a search-and-replace on a string for a given
    number of occurrences, but works from the back to the front.

    :param s: string to manipulate
    :param old: substring to search for
    :param new: substring to replace with
    :param occurrence: number of occurrences
    :return: Modified string.
    """
    li = s.rsplit(old, occurrence)
    return new.join(li)