Hi --

On Tue, 14 Jul 2009, Axel Schmalowsky wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> David A. Black wrote:
>> Hi --
>>
>> On Tue, 14 Jul 2009, Glenn Jackman wrote:
>>
>>>    case string
>>>    when /,/       then puts "#{string.inspect} contains a comma"
>>>    when /^[^,]*$/ then puts "#{string.inspect} has no comma"
>>>    end
>>
>> That second regex, on its own, won't tell you the whole story:
>>
>>    string = <<-EOM
>>    Hi.
>>    I have, at a minimum, two commas.
>>    Bye.
>>    EOM
>>
>>    p "Match!" if /^[^,]*$/.match(string)
>>      => Match!
>>
> Technically, the regexp above always succeeds (iirc).
> Even though the regexp is delimited by ^ and $,
> it matches always as along as the string against which the regexp is applied
> does not consist of only a single comma ('[^,]* -- match everything
> (including nothingness) but a comma).
>
> So, I guess it's better to simply use /,/.

Ha -- yes, it does indeed always match. I was too focused on the ^$
vs. \A\z thing to pick up on the * thing :-)


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)