Regex 对^(```求反并重复其元素
假设这样一个降价文件Regex 对^(```求反并重复其元素,regex,python-3.x,Regex,Python 3.x,假设这样一个降价文件 In [86]: !cat formatCase.md Some content in the head ``` >>> '{:20,.2f}'.format(18446744073709551616.0) '18,446,744,073,709,551,616.00' ```
In [86]: !cat formatCase.md
Some content in the head
```
>>> '{:20,.2f}'.format(18446744073709551616.0)
'18,446,744,073,709,551,616.00'
```
When formatting an integer, include the comma after the width:
```
>>> '{:20,d}'.format(18446744073709551616)
'18,446,744,073,709,551,616'
```
some content on the foot.
我想将语言类型添加到```
In [88]: c = open("new_format.md").read()
new_c = re.sub(r"```([^`]+)```", r"```python\1```",c)
此解决方案有效,还有一步,如果在``中存在输入错误的情况,则会出现一个``或两个``错误 然后,应将[^`]替换为^(```) 交替尝试
r"```(^(```))+```"
r"```(?:^(?:```))+```"
r"```((?:^(?:```))+)```"
它不能正确执行
如何能做到这一点,考虑^(`)情况。 你可以使用
r'```([^`]*(?:``?(?!`)[^`]*)*)```'
见
详细信息
-3个倒勾`
-第一组:([^`]*(?:``?(?!`)[^`]*)
-0+除反勾号以外的字符[^`]*
-零次或多次重复(?:``?(?!`)[^`]*)*
-1或2个反勾号后面没有另一个反勾号`?(?!`)
-0+除反勾号以外的字符[^`]*
-3个倒勾`