0

Before:

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

Is it possible to find whatever is between | and ]], and then use it to replace "wikiwoordenboek audio"

After:

=={{int:filedesc}}==
{{Information
|description = Example
|date =
|source =
|author =
|permission =
|other_versions =
}}
[[Category:Dutch pronunciation|Example]]
  • You should show your desired output. Should the line containing `wikiwoordenboek audio` become `|description = Example`? Is the pattern match triggered by `|description =` or `wikiwoordenboek audio` or something else? Is the whole block of text in memory? Is there anything else in the memory, or just this content? Should the last line be left unmodified? Which sub-species of 'regex' are you using? Is the host language Python or something else? – Jonathan Leffler Apr 18 '16 at 23:57
  • Can you please show an example of what you would like your "after" text to look like? Your string `|(.*)]]` would seem to be a syntax error for Wiki markup, so I think it should be `|(.*)}}`. – Ken Y-N Apr 18 '16 at 23:57
  • Try [`(?s)[\r\n]*\|.*?]]`](https://regex101.com/r/sC9dK6/1) – Wiktor Stribiżew Apr 18 '16 at 23:58
  • `s/\|[^\]]+\]\]/|wikiwoordenboek audio]]/g` – YOU Apr 19 '16 at 00:04
  • @JonathanLeffler Desired output added. Host language python. Description that needs to be replaced stays consistent, additional text may appear in front of source, date etc. – Ryan Huntley Apr 19 '16 at 00:24
  • @KenY-N (.*) is not part of the wiki mark up, hence not being in the code block. I have added the desired output – Ryan Huntley Apr 19 '16 at 00:27

2 Answers2

0

Try this

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

Regex demo

Tim007
  • 2,557
  • 1
  • 11
  • 20
  • I apologize for my poor question, what I meant got lost in translation. As shown by the desired output that I have added to the original question, I am looking for it to replace "wikiwoordenboek audio" in the description line, not the category line. – Ryan Huntley Apr 19 '16 at 00:26
0

Using 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}}'
framawiki
  • 242
  • 1
  • 10