I am trying to group all the repeated letters in a string.
Eg:
"aaaaaaabbbbbbbbc" => [['aaaaaaa'],['bbbbbbbb'],['c']]
Using logic and Ruby, the only way I could find to reach my intention was:
.scan(/(?:a+|A+)|(?:b+|B+)|(?:c+|C+)| ..... (?:y+|Y+)|(?:z+|Z+))
where ...
are the other alphabet letters.
There is a way to Dry that RegEx?
I used backtrace (\1)
too, but it doesn't match the single words and it doesn't return me the exact letters match => (\w+)\1
=> [['aa'],['bb']]
Uhm, am I wrong to use the regular expressions for this case and I should use Ruby methods with iterations?
I will glad to hear your opinion :) Thanks!