import re
regex = re.compile(r"<assign.*?>")
test_str = ("<if VERSION=\"A1\" || VERSION=\"A3\" || VERSION=\"a2_%5C%22A3\">\n\n"
"<assign CTA=\"blue\">\n"
"<assign CTA2=\"green\">\n"
"<assign TEXT1=\"Hello%3Cbr/%3EWorld\">\n\n"
"<elseif attribute-name=\"A2\">\n\n"
"<assign CTA=\"red\">\n"
"<assign CTA2=\"yellow\">\n"
"<assign CTA3=\"brown\">\n"
"<assign TEXT1=\"Click%20%3Ca%20href='https://example.com'%20style='text-decoration:none;color:#000000;'%3Ehere%3C/a%3E\">\n\n"
"</if>\n\n"
"// condition 2\n"
"<if FOO_BAR=\"A4\" || baz-biz=\"A5\">\n\n"
"<assign CTA=\"purple\">\n"
"<assign CTA2=\"orange\">\n"
"<assign TEXT1=\"Hi%20%3Cspan%20style='font-%20weight:bold;'%3EJohn%3C/span%3E\" TEXT2=\"Hello%3Cbr/%3EWorld\">\n\n"
"</if>\n\n"
"// condition 3\n"
"<if LANG=\"en_US\">\n\n"
"<assign TITLE=\"English\">\n\n"
"</if>")
subst = "$&</assign>"
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