From: Rick DeNatale on 11 Jul 2010 19:22 On Sun, Jul 11, 2010 at 4:53 PM, Brian Candler <b.candler(a)pobox.com> 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. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
First
|
Prev
|
Pages: 1 2 Prev: What does this mean? Next: Basic Question: How do you check to see if gets is a num |