Use re.sub instead of rstrip.

Be careful with rstrip. It will remove all characters matching those in the
given string, regardless of order. For example, if x = "temp.py", then
x.rstrip(".py") would be "tem".