Reputation: 11042
I want to find out more than 4 consecutive repeating characters within a string. e.g. (string is lowercased)
bbaaaaa ---> yes (5 consecutive a's)
bbaa ---> no
aabbbbbccdddddee ---> yes (5 consecutive b's)
One possible solution is to loop over a
to z
and use character{4,}
where character
can be anyone from a
to z
.
Is there any one liner for it?
I apologize if its duplicate
Upvotes: 2
Views: 2989
Reputation: 67988
import re
[i for i,j in re.findall(r"((.)\2{3,})",test_str)]
This should do it for you.
Output:
['aaaaa', 'bbbbb', 'ddddd']
Upvotes: 4