From: Rick DeNatale on
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