From: "David A. Black" Date: 2010-07-12T09:21:53+09:00 Subject: Re: Basic Question: How do you check to see if gets is a number? ---993115281-1000354610-1278894079=:15059 Content-Type: MULTIPART/MIXED; BOUNDARY="-993115281-1000354610-1278894079=:15059" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---993115281-1000354610-1278894079=:15059 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Mon, 12 Jul 2010, Rick DeNatale wrote: > On Sun, Jul 11, 2010 at 4:53 PM, Brian Candler wrote: >>> if age =~ /^d+$/ �# for an integer >> >> except that particular regexp allows strings which are not just numbers, >> e.g. >> >>>> age = "foo\n123\nbar" >> => "foo\n123\nbar" >>>> puts "oops" if age =~ /^\d+$/ >> oops >> => nil >> >> Use \A and \z to match start and end of the string. > > In general you are right, but ignoring my typo leaving out the \ in > \d, in this case the string came from gets so the multi-line string > case won't arise. >> $/ = "r" => "r" >> str = gets foo 123 bar => "foo\n123\nbar" Yes, yes, I know :-) David -- David A. Black, Senior Developer, Cyrus Innovation Inc. The Ruby training with Black/Brown/McAnally Compleat Stay tuned for next event announcement! Rubyist http://www.compleatrubyist.com ---993115281-1000354610-1278894079=:15059-- ---993115281-1000354610-1278894079=:15059--