字符串如下"hello how are you and huhuhu"
像这样"helo how are you and hu"
我试过这个正则表达式
re.sub(r'(\w)\1{1,}', r'\1', st)
这在删除一个相邻的重复字母时工作得非常好
例如"xcccc xcxcxcxc xxxxxcc"
结果是"xc xcxcxcxc xc"
。在
但我希望删除一个和两个不同的相邻重复字母。在
例如"xcccc xcxcxcxc xxxxxcc",
结果必须是这样的"xc xc xc"
。在
我希望这有助于理解我的问题并消除歧义。在
Tags:
使用regex,您可以这样做:
输出:
^{pr2}$或者:
输出:
^{pr2}$一种方法:
相关问题 更多 >
编程相关推荐