From: Fosiul Alam Date: 2012-08-16T05:21:54+09:00 Subject: Re: string processing Peter Hickman wrote in post #1072475: > 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 > end > > __END__ > uk-xxxxxxx-Z15A14 > Adding uk-xxxxx-Z15A14 (uk-xxxx-Z15A14) as "Generic SNMP-enabled Host" > using SNMP v1 with community "public" > Success - new device-id: (26) > > The $1 is the captured value, the (\d+) part. Hi thanks but there is a problem , I have modified this as bellow DATA.each do |line| if line =~ /^Success - new device-id: \((\d+)\)/ device_id = $1 end end puts #{device_id} and this does not return anything .. how can i use the value outside of the loop ?? i will try rest of the solution as well. thanks you guys .. -- Posted via http://www.ruby-forum.com/.