From: Timothy Hunter Date: 2006-08-25T09:18:38+09:00 Subject: Re: Determinig if 3 characters in a row are the same? 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. > > If by "character" you mean any character then this will do the trick: irb(main):004:0> m = /(.)\1\1/.match('zyzyzxxx010101') => # irb(main):005:0> m[0] => "xxx" irb(main):006:0> m = /(.)\1\1/.match('zyzyzxyx010101') => nil If you meant "alphabetic character" or "alpha-numeric character" then it needs a bit of tweaking.