import re
regex = re.compile(r"<ul.*?class=([\'\"])(?:s|bbc)\1[^>]*>(.*?)(?=\<\/ul\>)<\/ul>", flags=re.IGNORECASE)
test_str = ("<ul class=\"bbc\"><li>mierda</li></ul>\n\n"
"<ul class=\"bbc bbcol decimal\">\n"
"<li>mierda</li>\n"
"<li>mierda</li>\n"
"</ul>\n\n"
"<ul class=\"bbc\"><li>mierda</li></ul>")
subst = "[list]$2[/list]"
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