import re
regex = re.compile(r"<(?>\"[^\"]*\"|[^\">]+)*>(*SKIP)(*F)|(?<=[A-Za-z])=+(?=(?>\"[^\"]*\"|[^\"<]+)+<\/)")
test_str = ("<DT><H3 ADD_DATE=\"1727566144\" LAST_MODIFIED=\"1727566144\">produksjonsunderlag=production basis=()(أساس الإنتاج )</H3> \n\n"
"<DT><H3 ADD_DATE=\"1727566144\" LAST_MODIFIED=\"1727566144\">produksjonsunderlag|production basis|()(أساس الإنتاج )</H3> \n\n"
"<DT><H3 ADD_DATE=\"1727566144\" LAST_MODIFIED=\"1727566144\">antitrust==(مكافحة الاحتكار)</H3>\n"
"<DL><p> \n\n"
"<DT><H3 ADD_DATE=\"1727566144\" LAST_MODIFIED=\"1727566144\">**antitrust|(مكافحة الاحتكار)**</H3>\n"
"<DL><p> ")
subst = "|"
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