import re
regex = re.compile(r"<url>\s*<loc>[^<]+login.+?</url>\s*", flags=re.DOTALL)
test_str = ("<url>\n"
"<loc>http://review-pref.ru/literatura/49/131/</loc>\n"
"<changefreq>monthly</changefreq>\n"
"<priority>0.3</priority>\n"
"</url>\n"
"<url>\n"
"<loc>http://review-pref.ru/folklor/4/178/4/javascript/login</loc>\n"
"<changefreq>monthly</changefreq>\n"
"<priority>0.3</priority>\n"
"</url>\n"
"<url>\n"
"<loc>http://review-pref.ru/literatura/56/65/login/javascript/login/login/</loc>\n"
"<changefreq>monthly</changefreq>\n"
"<priority>0.3</priority>\n"
"</url>\n"
"<url>\n"
"<loc>http://review-pref.ru/folklor/4/164/</loc>\n"
"<changefreq>monthly</changefreq>\n"
"<priority>0.3</priority>\n"
"</url>\n")
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