Hi -- On Fri, 26 Jun 2009, Peter Bailey wrote: > Hello. > I need to parse through thousands of TIFF files and do some re-naming. > These files have underscores in them followed by a sequential number. I > need to grab just the "root" of the filename, without the underscore or > the numbers. > Dir.chdir("L:/infocontiffs/ehs-g7917741") > files = Dir.glob("*.tiff") > file = files[0] > puts file > file = file.gsub(/^(.*)_[0-9]+\.tiff/, "#{$1}") > puts file > What I get with this is: > ehs-g7917741_01.tiff > Why doesn't it give me my root filename? Here's another good use of the string[//] technique: >> file = "ehs-g7917741_01.tiff" => "ehs-g7917741_01.tiff" >> file[/[^_]+/] # match non-underscore characters => "ehs-g7917741" David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) "Ruby 1.9: What You Need To Know" Envycasts with David A. Black http://www.envycasts.com