import re
regex = r"(.)\1+"
test_str = "sentence = Eveeery mondayyy I waaake upp"
# use \\1\\1 if you need to replace with two characters and so on
subst = "\\1"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0)
if result:
print (result)
re.sub()
解决方案:输出:
[a-z]
-只匹配字母字符(字母)\1
-对第一个捕获组的反向引用,即([a-z])
\\2
-指向第二个捕获的(带圆括号的)组值你必须反复阅读这个句子的字母,而柯平跟踪上一个字母,以及它被看到了多少次。你知道吗
输出:
给你一个好的开始: 只需发布一个示例,它可能会帮助您:
输出:
希望这有帮助
相关问题 更多 >
编程相关推荐