From: Cheyne Li Date: 2008-05-09T05:27:34+09:00 Subject: wired result Hey, guys. I'm a new ruby learner. I'm so stuck on the regular expression part. The following code is a fuction that passed in 2 strings: ftarget, which is the location of a file to read; fkey is the key to match in the file. The function simply does open the file, read each line and try to find if there is a match fkey. I tested the i=0 line.scan(fkey){|x|i=i+1} puts i if i>0 puts "Found match...\n\r" end def fcmp(ftarget,fkey) @argc=ftarget puts fkey unless ftest(ftarget) puts "Invalid File name" return false end File.open(ftarget, 'r') do |f1| while line = f1.gets puts line i=0 line.scan(fkey){|x|i=i+1} puts i if i>0 puts "Found match...\n\r" end #return false end end end -- Posted via http://www.ruby-forum.com/.