我想找出一个字符串中超过 4 个连续重复的字符。例如(字符串小写)
bbaaaaa ---> yes (5 consecutive a's)
bbaa ---> no
aabbbbbccdddddee ---> yes (5 consecutive b's)
一个可能的解决方案是将 a
循环到 z
并使用 character{4,}
where character
可以是从 a
到 z
的任何值。
是否有任何一种衬垫?
如有重复,我深表歉意
最佳答案
import re
[i for i,j in re.findall(r"((.)\2{3,})",test_str)]
这应该为您完成。
输出:
['aaaaa', 'bbbbb', 'ddddd']
关于python - 用于查找字符串中超过 4 个连续重复字符的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34848208/