From: Brian Candler Date: 2010-09-19T03:41:34+09:00 Subject: Re: Ruby regexpresion, error? :-( iMelody Ooo wrote: > Dear Brian Candler, thank you very much, but still have problem. > > I read a line from file,want to macth ";" > > f = File.open(filename) > f.each do|line| > puts line > puts line.match( %r{;$}) > puts line.match( %r{;\z}) > puts line.match( %r{(.*);$}) > puts line.match( %r{(.*);\Z}) > end > > result: > ABC DEF=""; > nil > nil > nil > nil Change puts line to puts line.inspect Then you'll see that the line you've read is probably "ABC DEF=\"\";\n" (i.e. there's a newline at the end. \" is how inspect shows a double-quote within a double-quoted string) I would have expected %r{(.*);$} to match though: >> line = "ABC DEF=\"\";\n" => "ABC DEF=\"\";\n" >> line =~ %r{(.*);$} => 0 -- Posted via http://www.ruby-forum.com/.