How to 2 string from hostname

hostname
bd-vs-55.bd.domain.lan

I just want to convert this so that i can this(capital)

BD55

How can i get that ??
Thanks for help

On Tue, Sep 4, 2012 at 3:37 PM, Ferdous ara [email protected]
wrote:

hostname
bd-vs-55.bd.domain.lan

I just want to convert this so that i can this(capital)

BD55

How can i get that ??
Thanks for help

Which bd are you getting: the first one before the dash or the second
one, between the dots?
If it’s the first one:

s = ‘bd-vs-55.bd.domain.lan’
s.match(/(\w+?)-\w+?-(\d+)/).captures.join.upcase
=> “BD55”

If the second:

s = ‘bd-vs-55.bd.domain.lan’
s.match(/-(\d+).(\w+?)./).captures.reverse.join.upcase
=> “BD55”

Jesus.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs