import re
regex = re.compile(r"<Field name=\"Activity ID\">((.|\n)*?)</Field>", flags=re.IGNORECASE)
test_str = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<appointments>\n"
" <appointment>\n"
" \n"
" <Field name=\"Activity Date\">2013-11-08</Field>\n"
" <Field name=\"Activity Queue\">546278</Field>\n"
" <Field name=\"Activity Status\">cancelled</Field>\n"
" <Field name=\"Customer Name\">John Smith</Field>\n"
" <Field name=\"Activity ID\"> 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 1-John Smith (menor)\n"
" 5 (menor) 411 8\n"
"</Field> <Field name=\"Is a VIP\">1</Field>\n"
" </appointment>\n"
" <appointment>\n"
" \n"
" <Field name=\"Activity Date\">2-013-11-08</Field>\n"
" <Field name=\"Activity Queue\">2-546278</Field>\n"
" <Field name=\"Activity Status\">2-cancelled</Field>\n"
" <Field name=\"Customer Name\">2-John Smith</Field>\n"
" <Field name=\"Activity ID\">(menor) 2- 411 8(menor)\n"
"</Field> <Field name=\"Is a VIP\">2-</Field>\n"
" </appointment>\n"
"</appointments>\n")
subst = "a"
result = regex.sub(subst, test_str)
if result:
print(result)
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