From: "David A. Black" Date: 2007-10-26T03:50:21+09:00 Subject: Re: Change a string to an integer, report an error if the string does not represent an integer? Hi -- On Fri, 26 Oct 2007, 7stud -- wrote: > Ugh. This is much faster: > > strings = ['0013abc', '0025', '-0030', '+051', '00-1', '-abc72'] > > strings.each do |str| > if str.match(/^(\-|\+)?\d+$/) > puts str.to_i > else > puts "invalid int" > end > end Although.... strings = ["0025\nhello"] # will print 25 You want \A and \z, rather than ^ and $. David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!