Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Parse a String

Reply
Thread Tools

Parse a String

 
 
Sean Warburton
Guest
Posts: n/a
 
      01-22-2010
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.

TIA

Warby

Attachments:
http://www.ruby-forum.com/attachment/4407/test.txt

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jesús Gabriel y Galán
Guest
Posts: n/a
 
      01-22-2010
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 =<<EOF
irb(main):002:0" Domain name:
irb(main):003:0" suburbia.co.uk
irb(main):004:0"
[...]

irb(main):053:0> m = data.match(/Renewal date:\s+(.*)/)
=> #<MatchData "Renewal date: 28-Oct-2009" 1:"28-Oct-2009">
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.

 
Reply With Quote
 
 
 
 
Sean Warburton
Guest
Posts: n/a
 
      01-22-2010


Thank you, I'll try your suggestion.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Phillip Gawlowski
Guest
Posts: n/a
 
      01-23-2010
On 23.01.2010 02:02, Jay Crouch wrote:
> Hello,


Hello!

First things first: A subject line isn't optional, but helps us in
picking through the mails to find out what we can help with / are
interested in.

> I'm new to ruby/rails and am building out models right now.


> Thanks in advance for any help/clarification.


Second, you'll have better luck on the Rails mailing lists:
http://rubyonrails.org/community

While every Rails user uses Ruby, not every Ruby user uses Rails.

--
Phillip Gawlowski

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Is there a buit-in method to parse a STYLE attribute string? Henri ASP .Net 2 11-29-2004 02:59 AM
Perl - Parse UNC Path in a string variable Kevin Joseph Perl 5 08-13-2004 11:56 AM
parse string Vincent Perl 2 12-16-2003 08:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57