Example:
This has desired effect:
Replace the following with blank:
<tag condition="MyCondition">Text</tag>
Via:
string = re.sub('<tag condition=\"MyCondition\">.+</tag>', '', string)
But consider the following:
<tag2 condition="myCondition2">
<tag>Text</tag> and <tag>text</tag> is here.
</tag2>
And that I want to replace tag2
and all contents with blank eg:
string = re.sub('<tag2 condition=\"myCondition2\">.+</tag2>', '', string)
It is not removing tag2
and contents and I think it might be because there are <tags>
within tag2
.
How do I replace tag2
and all contents with blank?