On Fri, 25 Aug 2006, Ben Johnson wrote:

> Sorry for the noob question, but is there a fast and efficient way to
> determine if there are 3 of the same charater in a row in a string? I'm
> sure this could be done in regex but I am not a black belt in regex.
>
> thanks for your help.

   harp:~ > cat a.rb
   require 'yaml'

   re = %r/(...*?)\1/

   %w[
     a
     ab
     abc
     abcd
     abcabc
     abcdabcd
     abcdeabcde
   ].each{|word| y "word" => word, "word[re]" => word[re]}

   harp:~ > ruby a.rb
   word: a
   word[re]:
   word: ab
   word[re]:
   word: abc
   word[re]:
   word: abcd
   word[re]:
   word: abcabc
   word[re]: abcabc
   word: abcdabcd
   word[re]: abcdabcd
   word: abcdeabcde
   word[re]: abcdeabcde

kind regards.

-a
-- 
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dalai lama