Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2958
| X-FeedAbuse | http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 |
|---|---|
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!talisker.lacave.net!lacave.net!not-for-mail |
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Re: Extract a range i.e. svr? |
| Date | Fri, 15 Apr 2011 12:36:08 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 77 |
| Message-ID | <179b1d9eb1df11dd8b91b81c3a6faabb@ruby-forum.com> (permalink) |
| References | <a09ed402a715adbb77804d95cdf94bf2@ruby-forum.com> <BANLkTikF=HrdQnu9DQTnp-Buzr6dtnMjLQ@mail.gmail.com> |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | Quoted-printable |
| X-Trace | talisker.lacave.net 1302889918 29897 65.111.164.187 (15 Apr 2011 17:51:58 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Fri, 15 Apr 2011 17:51:58 +0000 (UTC) |
| In-Reply-To | <BANLkTikF=HrdQnu9DQTnp-Buzr6dtnMjLQ@mail.gmail.com> |
| X-Received-From | This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway |
| X-Mail-Count | 381651 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <179b1d9eb1df11dd8b91b81c3a6faabb@ruby-forum.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:2958 |
Show key headers only | View raw
"Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> wrote in post
#993035:
> Sorry, if I didn't understand this well. You have a string containing
> "svr[100..130].domain.local" and you want:
>
> svr100.domain.local
> svr101.domain.local
> ....
> svr130.domain.local
>
> ?
>
> If that's the case, then this might work:
>
> a = "svr[100..130].domain.local"
> m = a.match(/(.*?)\[(\d+)\.\.(\d+)\](.*)/)
> (m[2].to_i..m[3].to_i).each {|num| puts "#{m[1]}#{num}#{m[4]}"}
>
Here's my version:
str = "svr[100..130].domain.local"
range_pattern = /
\[ #a literal opening bracket
(\d+) #capture a series of one or more digits
[.]{2} #two literal periods
(\d+) #capture a series of one or more digits
\] #a literal closing bracket
/xms
before_range, the_range, after_range = str.partition(range_pattern)
start_range, end_range = $1, $2
start_range.upto(end_range) do |i|
puts "#{before_range}#{i}#{after_range}"
end
--output:--
svr100.domain.local
svr101.domain.local
svr102.domain.local
svr103.domain.local
svr104.domain.local
svr105.domain.local
svr106.domain.local
svr107.domain.local
svr108.domain.local
svr109.domain.local
svr110.domain.local
svr111.domain.local
svr112.domain.local
svr113.domain.local
svr114.domain.local
svr115.domain.local
svr116.domain.local
svr117.domain.local
svr118.domain.local
svr119.domain.local
svr120.domain.local
svr121.domain.local
svr122.domain.local
svr123.domain.local
svr124.domain.local
svr125.domain.local
svr126.domain.local
svr127.domain.local
svr128.domain.local
svr129.domain.local
svr130.domain.local
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 11:08 -0500
Re: Extract a range i.e. svr[100..130] ? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-15 11:41 -0500
Re: Extract a range i.e. svr? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-15 12:36 -0500
Re: Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 13:24 -0500
Re: Extract a range i.e. svr[100..130] ? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-15 13:27 -0500
Re: Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 13:40 -0500
Re: Extract a range i.e. svr[100..130] ? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-15 15:50 -0500
Re: Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 13:46 -0500
Re: Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 15:11 -0500
Re: Extract a range i.e. svr[100..130] ? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-18 15:33 -0500
Re: Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 16:48 -0500
Re: Extract a range i.e. svr[100..130] ? Richard Sandoval <skolopen@yahoo.com> - 2011-04-15 16:54 -0500
Re: Extract a range i.e. svr[100..130] ? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-15 17:03 -0500
csiph-web