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

···

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

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.

···

On Tue, Sep 4, 2012 at 3:37 PM, Ferdous ara <lists@ruby-forum.com> 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