On Wed, Aug 15, 2012 at 9:30 PM, Peter Hickman
<[email protected]> 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/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to