ruby - How do I match repeated characters? -


how find repeated characters using regular expression?

if have aaabbab, match characters have 3 repetitions:

aaa 

try string.scan(/((.)\2{2,})/).map(&:first), string string of characters.

the way works looks character , captures (the dot), matches repeats of character (the \2 backreference) 2 or more times (the {2,} range means "anywhere between 2 , infinity times"). scan return array of arrays, map first matches out of desired results.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

React Native allow user to reorder elements in a scrollview list -

multithreading - Exception in Application constructor -