From: Fosiul Alam Date: 2012-08-16T05:28:59+09:00 Subject: Re: string processing Eliezer Croitoru wrote in post #1072477: > On 8/15/2012 10:00 PM, Fosiul Alam wrote: >> >> will it work ?? >> > this output should be a string and is not enumerable so you can use each > but you can use "each_line" to inspect each line but "getnumber = item" > will not extract the number. > and instead of iterating over each line you can use one regex on the > whole string like: > cmd =~ /\((\d+)\)/ > > you must use "\d+" to match one or more numbers > the =~ will give bad results on a whole string and you better use the > scan method. > cmd.scan /\((\d+)\)/ > this will return array of strings array > so this: > (cmd.scan /\((\d+)\)/)[0][0] > will give you the result with a one liner. > and i just seen that Robert gave you a nice solution. > > Regards, > Eliezer Hi thanks this works perfec host=ARGV[0] puts host cmd=`php -q /var/lib/cacti/cli/add_device.php --description="#{host}" --ip="#{host}" --template=1 --community="public"` device_id = (cmd.scan /\((\d+)\)/)[0][0] puts device_id -- Posted via http://www.ruby-forum.com/.