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