def rreplace(s, old, new, occurences=-1):
    """Replace all occurencens of 'old' with 'new'
    starting at the right hand side of the string. If occurences
    is specified, the number of replacements is limited to
    occurences.

    :param s: the input string
    :type s: string
    :param old: the string that will be replaced
    :type old: string
    :param new: the replacement string
    :type new: string
    :param occurences: the maximal number of replacements
    :type occurences: integer
    """
    li = s.rsplit(old, occurences)
    return new.join(li)