From: Michael Guterl Date: 2006-11-05T02:19:10+09:00 Subject: Re: How could I do this search using .scan - I am a newbie ------=_Part_26278_23077713.1162660746665 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/4/06, Kevin Stolt wrote: > > Thx for ur help....but this is just searching for 'rat' isn't it? > thats not going to work> > > what I am looking is to find anything in the second column. I am not > sure how to explain otherwise..... IO.foreach("foo.txt") do |line| puts line.split[1] end This is assuming your file is called foo.txt Li Chen wrote: > > Kevin Stolt wrote: > >> Hi, > >> > >> I am new to ruby and I have been search and pulling my hair to do this > >> using .scan? > >> > >> I have file which contains.....(this is an example) > >> > >> bat rat cat mat pat > >> mat sat put tomorrow today > >> > >> > >> So how could I search so I could get the values in the second column? > >> > >> I want to find "rat" and "sat" for example. I searched many time and > >> read many things but I can't figure out. I hope someone would be kind > >> enough to help me or show me the correct direction. > >> > >> any help is appreciated. > >> > >> thanks in advance > >> kev > > > > I don't know what you want but the following might show you some clues: > > > > C:\>irb > > irb(main):001:0> line='bat rat cat mat pat' > > => "bat rat cat mat pat" > > irb(main):002:0> re=Regexp.new('rat') #create a regular expression > > abject > > => /rat/ > > irb(main):004:0> puts re.match(line) # match the regexp against the > > string > > rat > > => nil > > > > > > Li > > > -- > Posted via http://www.ruby-forum.com/. > > HTH, Michael Guterl ------=_Part_26278_23077713.1162660746665--