Let's say I've got the following wikitext:
Some stuff More stuff {{MyTemplate}}<!-- comment --> Blah Blah
I want to find {{MyTemplate}} but only if it's immediately followed by <!-- comment -->, and insert something after the comment. Is there anything that does that kind of pattern matching? I can use mwparserfromhell to find the template:
for node in wikicode.nodes: if isinstance(node, mwp.nodes.Template) and node.name.matches("MyTemplate"):
but I don't see any way to match on two consecutive nodes without building my own little state machine in the loop to keep track of what the previous node was.