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? > Thanks, > Peter Is this what you want? while fname = DATA.gets m = fname.match /(.*?)_\d+\.tiff/ if m puts "Match: '#{m[1]}'" else puts "No match: #{fname}" end end __END__ ehs-g7917741_01.tiff asadsasd_12345.tiff ljhkjhkh_1_2_3.tiff xxxx__1.tiff xxxx_.tiff xxxx.tiff xxxx _.tiff _01.tiff -- Posted via http://www.ruby-forum.com/.