在Python中有没有一种快速的方法可以替换字符串,但是不像replace
那样从开头开始,而是从结尾开始呢?例如:
>>> def rreplace(old, new, occurrence)
>>> ... # Code to replace the last occurrences of old by new
>>> '<div><div>Hello</div></div>'.rreplace('</div>','</bad>',1)
>>> '<div><div>Hello</div></bad>'