From: Gilbert Rebhan Date: 2007-09-22T19:35:04+09:00 Subject: Re: regex problem with gsub Hi, Sebastian Hungerecker wrote: > Gilbert Rebhan wrote: >> str=File.basename(Dir["J:/test/*.xml"].sort[0]).gsub(/(\w{8}).+/, $1) > > At this point $1 is nil, which is why you get the error. You have to keep in > mind that arguments are evaluated before the method is called and $1 will > only have value after that. You need to use '\1' instead of $1. Thanks!! Works now. I'm still not sure, when to use \1 and when to use $1 Regards, Gilbert