From: Kevin Stolt Date: 2006-11-05T01:29:13+09:00 Subject: Re: How could I do this search using .scan - I am a newbie 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..... 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/.