import re
regex = re.compile(r"<NumDI>(?'num_externe'.*)<\x2FNumDI>.*<NomDemandeur>(?'apt_nom'.*)<\x2FNomDemandeur>.*<Installation>(?'ins_libl'.*)<\x2FInstallation>.*<Localisation>(?'apt_localisation'.*)<\x2FLocalisation>.*<Symptome>(?'tsy_lib'.*)<\x2FSymptome>.*<SousSymptome>(?'qsy_lib'.*)<\x2FSousSymptome>.*<DateSouhaitee>(?'dtheure_limite'.*)<\x2FDateSouhaitee>.*<Commentaires>(?'commentaire_externe'.*)<\x2FCommentaires>", flags=re.MULTILINE)
test_str = "<DEMANDE> <NumDI> 247902</NumDI> <NomDemandeur>BOURG</NomDemandeur> <Installation>84CA21558</Installation> <Localisation>ZAC,,,</Localisation> <Symptome>CHA2</Symptome> <SousSymptome>CHA2</SousSymptome> <Urgence>1</Urgence> <DateSouhaitee>15/05/2019</DateSouhaitee> <Commentaires>TEST DE CREATION DE DEMANDE</Commentaires> </DEMANDE> "
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html