Karl-Heinz Wild
9/25/2008 3:24:00 PM
On 25.09.2008, at 16:43, Lex Williams wrote:
> Considering that :
>
> a = "1112223334444"
>
> watch the following irb session :
>
> irb(main):010:0> a.scan(/((.)\2+)/).collect {|match| match[0]}
> => ["111", "222", "333", "4444"]
great idea!
... this will also match single letters / digits
irb(main):020:0> a = "11111122233344444445556667778888888AAABCCDEEEEF"
=> "11111122233344444445556667778888888AAABCCDEEEEF"
irb(main):021:0> puts a.scan( /((.)\2+|.)/ ).collect { |x| x[0] }
111111
222
333
4444444
555
666
777
8888888
AAA
B
CC
D
EEEE
F
regards
Karl-Heinz