正则表达式可以这样做吗?

时间:2016-04-18 23:42:41

标签: regex pywikibot

在:

=={{int:filedesc}}==
{{Information
|description = wikiwoordenboek audio
|date =
|source =
|author =
|permission =
|other_versions =
}}
[[Category:Dutch pronunciation|Example]]

是否可以找到|]]之间的任何内容,然后用它来替换" wikiwoordenboek audio"

后:

=={{int:filedesc}}==
{{Information
|description = Example
|date =
|source =
|author =
|permission =
|other_versions =
}}
[[Category:Dutch pronunciation|Example]]

2 个答案:

答案 0 :(得分:0)

试试这个

(\|description =\s*)([^\n]+)(.*\[\[)([^\|]+\|)([^]]+)

Regex demo

答案 1 :(得分:0)

使用mwparserfromhell

>>> import mwparserfromhell
>>> t = """=={{int:filedesc}}==
... {{Information
... |description = wikiwoordenboek audio
... |date =
... |source =
... |author =
... |permission =
... |other_versions =
... }}
... [[Category:Dutch pronunciation|Example]]"""
>>> for i in mwparserfromhell.parse(t).filter_templates():
...     if 'information' in i.name.lower():
...         i.get('description').value = 'Example'
... 
>>> t
u'{{Information\n|description =Example|date =\n|source =\n|author =\n|permission =\n|other_versions =\n}}'