python - 正则表达式替换 Python 中奇数重复出现的字符

标签 python regex replace

无法获取正则表达式来替换 Python 中奇数重复出现的字符。

例子:

char = ``...```.....``...`....`````...`

``...``````.....``...``....``````````...``

即使出现也不会替换。

最佳答案

例如:

>>> import re
>>> s = "`...```.....``...`....`````...`"
>>> re.sub(r'((?<!`)(``)*`(?!`))', r'\1\1', s)
'``...``````.....``...``....``````````...``'

关于python - 正则表达式替换 Python 中奇数重复出现的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433566/

相关文章:

python - Django 管理站点

excel - VBA Excel - 将 Enter 键替换为 Alt Enter

Java 点不匹配 'any character'

mysql - SQL查询以根据通配符替换字符串

python - 删除最小值、最大值和计算平均值

python - 星图与 tqdm 结合?

javascript - 为什么在 Javascript 中正则表达式字符串没有封装在引号中?

java - 将 Perl 正则表达式转换为 POSIX 正则表达式

python - 从数据文件中更改列表中的值

c++ - 如何匹配环境不同的两个群体? C++