From: Ryan Davis Date: 2012-09-03T06:30:52+09:00 Subject: Re: How to get part of a string On Sep 2, 2012, at 14:23 , Fosiul Alam wrote: > 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 That is working perfectly. There is no "US" anywhere in your string.