From: Jovino Date: 2007-09-22T20:14:48+09:00 Subject: Re: regex problem with gsub Hi Gilbert: The problem it's not the regex, it's the second parameter, try instead: string.gsub(/(\w{7}).+/, '\1') This supposing you want ever the first seven chars, if you want the characters before because they can be variable, try this regex: string.gsub(/(\w*)(_.*)*\..+/, '\1') I'm not mastered the regular expressions, any corrections appreciated. Regards, Jovino -----Mensaje original----- De: Gilbert Rebhan [mailto:mailforgilbert@gmx.de] Enviado el: s�bado, 22 de septiembre de 2007 11:55 Para: ruby-talk ML Asunto: regex problem with gsub Hi, i have a dir like that and need the first part of the first filename = J:\test>dir /B 20070921_0001.xml 20070921_0002.xml 20070921_0003.xml i tried with = str=File.basename(Dir["J:/test/*.xml"].sort[0]).gsub(/(\w{8}).+/, $1) but = TypeError: can't convert nil into String from (irb):4:in `gsub' from (irb):4 from :0 if i use = irb(main):005:0> str=File.basename(Dir["J:/test/*.xml"].sort[0]) => "20070921_0001.xml" i get the filename how to change my gsub part to make it work, i want the first part of the filename, i.e. filename "20070921_0001.xml" i want "20070921" Regards, Gilbert