Мне нужно удалить многострочный шаблон из файла.
Например:
<Command name="somecom" type="type" >
<input name="some input" />
<output name="some output" />
</Command>
<?ignore <Command name="somecom" type="type" >
<input name="some input" />
<output name="some output" />
</Command> ?>
Раздел для удаления начинается с:
<?ignore
Заканчивается на:
?>
Я хочу использовать регулярные выражения для этого. python3.6.3
with open('graph.xml', 'r') as readXML:
tempFile = readXML.read()
patr = re.compile("<?ignore.*?>", re.MULTILINE)
tempFile = re.sub(patr,"",tempFile)
print(tempFile)
Результат:
<Command name="somecom" type="type" >
<input name="some input" />
<output name="some output" />
</Command>
<?
<input name="some input" />
<output name="some output" />
</Command> ?>
Я хотел бы удалить весь раздел, а не только частичную первую строку.