I am trying to have a regular expression match a value that spans multiple lines. I am using the re.S flag, but still get no results. Any ideas why?
This is the text that I am searching through:
<File id="abc.txt" EngRev="74">
<Identifier id="STRING_ID" isArray="1" goesWith="3027253">
<EngTranslation>"Value 1","Value 2","Value 3","Value 4","Value 5",</EngTranslation>
<LangTranslation filename="abc.txt" key="STRING_ID 0">Value 1</LangTranslation>
<array filename="abc.txt" key="STRING_ID 1">Value 2</array>
<array filename="abc.txt" key="STRING_ID 2">Value 3</array>
<array filename="abc.txt" key="STRING_ID 3">Value 4</array>
<array filename="abc.txt" key="STRING_ID 4">Value 5</array>
</Identifier>
<Identifier id="STRING_ID2" isArray="0" goesWith="3027253">
<EngTranslation>"Value 1"</EngTranslation>
<LangTranslation filename="abc.txt" key="STRING_ID2">Value 1</LangTranslation>
</Identifier>
</File>
This is the code I am using to obtain a match:
def updateToArray(matchobj):
return matchobj.group(0).replace('LangTranslation','array')
outXML = re.sub(r'<Identifier.*?<array.*?</Identifier>', updateToArray, outXML, re.S)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…