Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Parse a String (http://www.velocityreviews.com/forums/t861359-parse-a-string.html)

Sean Warburton 01-22-2010 11:32 AM

Parse a String
 
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/.


Jesús Gabriel y Galán 01-22-2010 11:41 AM

Re: Parse a String
 
On Fri, Jan 22, 2010 at 12:32 PM, Sean Warburton
<sean_warburton@yahoo.co.uk> 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.


Sean Warburton 01-22-2010 11:49 AM

Re: Parse a String
 


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


Phillip Gawlowski 01-23-2010 02:23 AM

Re: Extending Rails models
 
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



All times are GMT. The time now is 05:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


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