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,
>>> age = "foo\n123\nbar"
> => "foo\n123\nbar"
>>> puts "oops" if age =~ /^\d+$/
> => 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.
First | Prev |
Pages: 1 2
Prev: What does this mean?
Next: Basic Question: How do you check to see if gets is a num