Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Extract a range i.e. svr[100..130] ?

Reply
Thread Tools

Extract a range i.e. svr[100..130] ?

 
 
Richard Sandoval
Guest
Posts: n/a
 
      04-15-2011
Here is what i am trying to do.



nodes = cfv.values.to_s.split(/[, \n]+/)
a = nodes
m = a.match(/(.*?)\[(\d+)\.\.(\d+)\](.*)/)

puts "nodes: #{m.inspect}"


m.each do |node|
puts "checking to see if #{node} exists"

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

 
Reply With Quote
 
 
 
 
Jesús Gabriel y Galán
Guest
Posts: n/a
 
      04-15-2011
On Fri, Apr 15, 2011 at 11:54 PM, Richard Sandoval <(E-Mail Removed)> wrote:
> Here is what i am trying to do.
>
>
>
> nodes = cfv.values.to_s.split(/[, \n]+/)


split returns an array
(http://ruby-doc.org/core-1.8.7/class...g.html#M000776). So you
can do the following:

nodes.each do |node|
m = node.match(/(.*?)\[(\d+)\.\.(\d+)\](.*)/)
if m
(m[2].to_i..m[3].to_i).each {|num|
do_something_with("#{m[1]}#{num}#{m[4]}")}
else
do_something_with(node)
end
end

This will call do_something_with passing either each expanded server
name or the original string if it doesn't match the regular
expression.

Jesus.

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      04-18-2011
Richard Sandoval wrote in post #993091:
> 7stud,
>
> you use upto but that doesnt work for 1.8.6, what method could I use in
> this scenario?


puts RUBY_VERSION

1.upto(5) do |i|
puts i
end

--output:--
1.8.6
1
2
3
4
5

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

 
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
How do i extract vidios when winrar wont extract them??? help plzzzzzzzz smuttdog@sc.rr.com Computer Support 2 12-23-2007 07:03 AM
extract a range start/end? Michael Linfield Ruby 8 09-03-2007 12:40 AM
range() is not the best way to check range? Summercoolness@gmail.com Python 46 07-25-2006 08:10 PM
Extract range of lines from a text file Amer Neely Perl Misc 29 04-10-2006 12:28 AM
extract range of lines using range op bug? it_says_BALLS_on_your forehead Perl Misc 3 03-03-2006 04:28 PM



Advertisments