# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(<Contract)(.*)(Contract>)"
test_str = ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Records xmlns=\"http://www.datapump.cig.com\">\n"
"<Contract phaseId=\"4\" operation=\"2\">\n"
" <General>\n"
" <ContractCode>8848</ContractCode>\n"
" <DateOfSignature>2009-09-08</DateOfSignature>\n"
" <CreditPurpose id=\"20\"/>\n"
" <NegativeStatus id=\"4\"/>\n"
" <ApplicationDate>2009-09-08</ApplicationDate>\n"
" <StartDate>2009-09-08</StartDate>\n"
" <ExpectedEndDate>2011-03-31</ExpectedEndDate>\n"
" <Subjects>\n"
" <Subject roleId=\"1\">\n"
" <Entity>\n"
" <Individual gender=\"1\">\n"
" <FirstName>\n"
"<Text language=\"uk-UA\">украинÑкий</Text>\n"
" </FirstName>\n"
" <Surname>\n"
"<Text language=\"uk-UA\">Первый</Text>\n"
" </Surname>\n"
" <FathersName>\n"
"<Text language=\"uk-UA\">контрагент</Text>\n"
" </FathersName>\n"
" <Classification id=\"1\"/>\n"
" <DateOfBirth>1980-12-06</DateOfBirth>\n"
" <Residency id=\"1\"/>\n"
" <Citizenship code=\"UA\"/>\n"
" <MaritalStatus id=\"2\"/>\n"
" <Identifications>\n"
"<Identification typeId=\"2\">\n"
"<Number>2554209876</Number>\n"
"</Identification>\n"
"<Identification typeId=\"4\">\n"
"<Number>ВЦ620997</Number>\n"
"<IssueDate>1997-04-01</IssueDate>\n"
"<Authority language=\"uk-UA\">ДебальцевÑкий ГОУМВД Украины в Донецкой облаÑти</Authority>\n"
"</Identification>\n"
"<Identification typeId=\"1\">\n"
" <Number>2554209876</Number>\n"
"</Identification>\n"
" </Identifications>\n"
" <Addresses>\n"
"<Address typeId=\"2\">\n"
"<Street>\n"
" <Text language=\"uk-UA\">м. Kharkov, вул. Street, буд. 1, кв. 1</Text>\n"
"</Street>\n"
"</Address>\n"
" </Addresses>\n"
" </Individual>\n"
" </Entity>\n"
" </Subject>\n"
" </Subjects>\n"
" </General>\n"
" <Type>\n"
" <Credit paymentPeriodId=\"9\" paymentMethodId=\"6\">\n"
" <CreditLimit currency=\"USD\">7800.0</CreditLimit>\n"
" <Records>\n"
" <Record accountingDate=\"2011-04-20\">\n"
" <CreditUsage id=\"3\"/>\n"
" <ResidualAmount currency=\"USD\">7800.0</ResidualAmount>\n"
" <OverdueAmount currency=\"USD\">0.0</OverdueAmount>\n"
" </Record>\n"
" </Records>\n"
" </Credit>\n"
" </Type>\n"
"</Contract>")
subst = ""
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.IGNORECASE | re.DOTALL)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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