# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(<CreditApplication ID=\x222222222\x22>)(\s+\S+.*\s+)+(<\/CreditApplication>)"
test_str = ("<CreditApplication ID=\"1111111\">\n"
" <CreditApplicationDetails>\n"
" <DecisionID>11223366</DecisionID>\n"
" <LenderReference>256548</LenderReference>\n"
" </CreditApplicationDetails>\n"
" <CreditApplicationHistoryLogs>\n"
" <Log ID=\"25486522\">\n"
" <Status>FULFILLED</Status>\n"
" <Timestamp>2018-06-02T11:52:05+01:00</Timestamp>\n"
" </Log>\n"
" </CreditApplicationHistoryLogs>\n"
" <ConsumerDetails>\n"
" <Title>Mr</Title>\n"
" <FirstName>ROXY</FirstName>\n"
" </ConsumerDetails>\n"
" <Decision ID=\"2255222\">\n"
" <PolicyName>Credit Strategy V20</PolicyName>\n"
" <DecisionStatus>ACCEPT</DecisionStatus>\n"
" <Timestamp>2018-06-02T11:38:36+01:00</Timestamp>\n"
" <Rule>\n"
" <RuleNumber>1</RuleNumber>\n"
" <RuleName>Applicant over 18 years old</RuleName>\n"
" </Rule>\n"
" <Rule>\n"
" <RuleNumber>140</RuleNumber>\n"
" <RuleName>Notice of correction found</RuleName>\n"
" </Rule>\n"
" </Decision>\n"
" <CreditSentryData>\n"
" <MobileStatus>1</MobileStatus>\n"
" </CreditSentryData>\n"
" </CreditApplication>\n"
" <CreditApplication ID=\"2222222\">\n"
" <CreditApplicationDetails>\n"
" <DecisionID>25252525</DecisionID>\n"
" <LenderReference>3636365</LenderReference>\n"
" </CreditApplicationDetails>\n"
" <CreditApplicationHistoryLogs>\n"
" <Log ID=\"454545\">\n"
" <Status>FULFILLED</Status>\n"
" <Timestamp>2018-06-02T11:52:05+01:00</Timestamp>\n"
" </Log>\n"
" </CreditApplicationHistoryLogs>\n"
" <ConsumerDetails>\n"
" <Title>Mr</Title>\n"
" <FirstName>AMIT</FirstName>\n"
" </ConsumerDetails>\n"
" <Decision ID=\"112255874\">\n"
" <PolicyName>Credit Strategy V20</PolicyName>\n"
" <DecisionStatus>ACCEPT</DecisionStatus>\n"
" <Timestamp>2018-06-02T11:38:36+01:00</Timestamp>\n"
" <Rule>\n"
" <RuleNumber>1</RuleNumber>\n"
" <RuleName>Applicant over 18 years old</RuleName>\n"
" </Rule>\n"
" <Rule>\n"
" <RuleNumber>140</RuleNumber>\n"
" <RuleName>Notice of correction found</RuleName>\n"
" </Rule>\n"
" </Decision>\n"
" <CreditSentryData>\n"
" <MobileStatus>1</MobileStatus>\n"
" </CreditSentryData>\n"
" </CreditApplication>\n"
" <CreditApplication ID=\"33665588\">\n"
" <CreditApplicationDetails>\n"
" <DecisionID>558454</DecisionID>\n"
" <LenderReference>669855</LenderReference>\n"
" </CreditApplicationDetails>\n"
" <CreditApplicationHistoryLogs>\n"
" <Log ID=\"254112\">\n"
" <Status>FULFILLED</Status>\n"
" <Timestamp>2018-06-02T11:52:05+01:00</Timestamp>\n"
" </Log>\n"
" </CreditApplicationHistoryLogs>\n"
" <ConsumerDetails>\n"
" <Title>Mr</Title>\n"
" <FirstName>KATY</FirstName>\n"
" </ConsumerDetails>\n"
" <Decision ID=\"254125\">\n"
" <PolicyName>Credit Strategy V20</PolicyName>\n"
" <DecisionStatus>ACCEPT</DecisionStatus>\n"
" <Timestamp>2018-06-02T11:38:36+01:00</Timestamp>\n"
" <Rule>\n"
" <RuleNumber>1</RuleNumber>\n"
" <RuleName>Applicant over 18 years old</RuleName>\n"
" </Rule>\n"
" <Rule>\n"
" <RuleNumber>140</RuleNumber>\n"
" <RuleName>Notice of correction found</RuleName>\n"
" </Rule>\n"
" </Decision>\n"
" <CreditSentryData>\n"
" <MobileStatus>1</MobileStatus>\n"
" </CreditSentryData>\n"
" </CreditApplication>")
subst = ""
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
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