我正在尝试使用 Python 从以下形式的 wikitext 模板中删除换行符:
{{cite web
|title=Testing
|url=Testing
|editor=Testing
}}
应使用 re.sub 获得以下内容:
{{cite web|title=Testing|url=Testing|editor=Testing}}
我一直在尝试使用 Python 正则表达式几个小时,但还没有成功。例如我试过:
while(re.search(r'\{cite web(.*?)([\r\n]+)(.*?)\}\}')):
textmodif=re.sub(r'\{cite web(.*?)([\r\n]+)(.*?)\}\}', r'{cite web\1\3}}', textmodif,re.DOTALL)
但它没有按预期工作(即使没有 while 循环,它也不适用于第一个换行符)。
我发现了这个类似的问题,但没有帮助:Regex for MediaWiki wikitext templates。我对 Python 很陌生,所以请不要对我太苛刻:-)
先感谢您。