Hi, I have a string s= XXaaXX, in which i want to replace the last substring r, which is determined at run time. r= XX s.gsub(/XX\z/,'') solves the problem in a static way. s.gsub(r,'') solves it too, but who can I specify, that only the last occurence should be replaced. Best regards, Tomas -- Posted via http://www.ruby-forum.com/.