From: Fosiul Alam Date: 2012-09-03T06:23:19+09:00 Subject: Re: How to get part of a string Robert Klemme wrote in post #1074348: > On Sun, Sep 2, 2012 at 7:37 PM, Fosiul Alam > wrote: >> /dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5 >> >> Some how i jus want to get whats the code for the cluster >> which is BD55 >> >> >> now /xxx/xxxx/ is same for every line and after US55(this value >> different for every server) there would be a - (BD55-) >> >> I would be really help full if any one can help me > > One way would be to read this line by line and use Regexp > > e.g. > > irb(main):001:0> line = '/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% > /xxx/xxxx/BD55-5' > => "/dev/cciss/c0d5p1 1.8T 88M 1.7T 1% /xxx/xxxx/BD55-5" > irb(main):002:0> line[%r{BD\d+(?=-\d$)}] > => "BD55" > Hi but its not working irb(main):001:0> line ='/dev/cciss/c0d11p1 /xxx/xxxxx/BD55-11 ext3 defaults,noatime,nodiratime 1 0' => "/dev/cciss/c0d11p1 /xxx/xxxx/BD55-11 ext3 defaults,noatime,nodiratime 1 0" irb(main):002:0> line[%r{US\d+(?=-\d$)}] => nil -- Posted via http://www.ruby-forum.com/.