From: Rajinder Yadav Date: 2009-12-27T02:42:04+09:00 Subject: Re: How to parse this file Hassan Schroeder wrote: > On Sat, Dec 26, 2009 at 9:03 AM, Rajinder Yadav wrote: > >> here is the basic code, output followed by a basic explanation > >> data=line.match /\"(\w+)\"\s+\"(\w+)\"/ > > ?? That won't remotely work, unless the "Question" and "Answer" > are both single words, which seems unlikely :-) > > Try something like line.chomp.match /\"([^"]+)\"\s+\"([^"]+)\"/ > >>> '"What is the temperature?" "Pretty cold"'.match /\"(\w+)\"\s+\"(\w+)\"/ > => nil >>> '"What is the temperature?" "Pretty cold"'.match /\"([^"]+)\"\s+\"([^"]+)\"/ > => # is the temperature?" 2:"Pretty cold"> >>> result = '"What is the temperature?" "Pretty cold"'.match /\"([^"]+)\"\s+\"([^"]+)\"/ > => # is the temperature?" 2:"Pretty cold"> >>> result[1] > => "What is the temperature?" >>> result[2] > => "Pretty cold" > I shouldn't reply when I am half awake =) -- Kind Regards, Rajinder Yadav http://DevMentor.org Do Good! - Share Freely