Hi --

On Mon, 20 Nov 2006, Robert Klemme wrote:

> Luca Scaljery <lcalje / gmail.com> wrote:
>> Hi All
>> 
>> I just tried to test the content of a string, something like this:
>> 
>> 
>> c = "1234AA"
>> 
>> if c.scan( /1234567890/ )
>>   p "OK"
>> else
>>   p "NO"
>> end
>> 
>> 
>> This always returns "OK" :(
>> 
>> Any suggestions what goes wrong here. And is this the way to check the
>> content of a string ?
>
> What exactly do you want to check?  If you want to make sure that a string 
> solely consists of digits this is what you would do:
>
> c = "1234AA"
>
> if /\A\d+\z/ =~ c

Or:

   unless /\D/ =~ c

:-)


David

-- 
                   David A. Black | dblack / rubypal.com
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org