From: "Jesús Gabriel y Galán" Date: 2010-01-22T20:41:29+09:00 Subject: Re: Parse a String On Fri, Jan 22, 2010 at 12:32 PM, Sean Warburton wrote: > Hello, > > I wonder if someone would be able to help. > > Through necessity I'm learning Ruby and trying to write my own script > and while I am getting there and grasping things more, I'm still on > first rung of the ladder and finding things difficult so please be > patient ;) > > Part of my script involves opening a telnet session and then sending a > whois request that returns a lot of text ... > > I've managed to get to the point where I have the reply stored in a > variable but what I would now like to do is parse the variable for bits > of the information and I have read and read but can't find something > that I seem to be able to understand. > > I have attached a text file with the data that my variable holds and I > need to parse out things like the "Renewal date:" and "Registration > status:". Would anyone be able to offer me some help on how I should go > about parsing. You should a bit about regular expressions. If the text has "simple" rules, regexes are usually enough to extract the pieces of data you need. In your case, for example: irb(main):001:0> data =< m = data.match(/Renewal date:\s+(.*)/) => # irb(main):054:0> m[1] => "28-Oct-2009" If your case is as simple as this, the above solution could be enough. Hope this helps, Jesus.