From: ricpelo@... Date: 2005-10-26T04:52:02+09:00 Subject: Weird thing with "sub" and "rjust" I would like to write code which does the following transformations: "hello-3.jpg" => "hello-003.jpg" "hello-42.jpg" => "hello-042.jpg" "hello-250.jpg" => "hello-250.jpg" And I tried this: string.sub(/(\d+)/, '\1'.rjust(3, '0')) where "string" is one of the above strings (in the left side of =>). It works with: 'hello-42.jpg'.sub(/(\d+)/, '\1'.rjust(3, '0')) => "hello-042.jpg" But it doesn't works with: 'hello-3.jpg'.sub(/(\d+)/, '\1'.rjust(3, '0')) => "hello-03.jpg" And doesn't works with: 'hello-250.jpg'.sub(/(\d+)/, '\1'.rjust(3, '0')) => "hello-0250.jpg" What's wrong? Thanks a lot.