From: Robert Klemme Date: 2012-08-16T04:40:56+09:00 Subject: Re: string processing On Wed, Aug 15, 2012 at 9:30 PM, Peter Hickman wrote: > You need to also make sure that you get the right line, not just pick > out the any digits > > DATA.each do |line| > if line =~ /^Success - new device-id: \((\d+)\)/ > puts $1 > end Alternatively num = line[/^Success - new device-id: \((\d+)\)/, 1] and puts num I find the solution with String#[] very elegant. :-) Btw, if there is always just one number this shorter solution will work as well - but is not so robust against other inputs: num = line[/\d+/] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/