From: Steel Steel Date: 2010-09-19T00:26:06+09:00 Subject: Re: Ruby regexpresion, error? :-( iMelody Ooo wrote: > Thank you,Steel Steel,But why cannot use regexpresion? > >> then do this >> f = File.open(filename) >> f.each do|line| >> puts line >> puts "found ;" if line[-1]==";" >> end yes you can use regexp. But your requirement is simple. So simple string indexing does the job. by the way, the reason why it did not work for you is that you have a newline character when a line is read. So just chomp it off f = File.open(filename) f.each do|line| line.chomp! puts "found ;" if line[-1]==";" end same to your regexp method f = File.open(filename) f.each do|line| puts line line.chomp! puts line.match( %r{;$}) puts line.match( %r{;\z}) puts line.match( %r{(.*);$}) puts line.match( %r{(.*);\Z}) end -- Posted via http://www.ruby-forum.com/.