def rreplace(string, old, new, occurrence):
    """A version of the str.replace() method which works from the right.
    Taken from https://stackoverflow.com/questions/2556108/
    """
    elems = string.rsplit(old, occurrence)
    return new.join(elems)
