import re
regex = re.compile(r"<(\w+) [^<>]*\bclass\s*=\s*\"[^\"]*\bmd\b[^\"]*\"[^<>]*>[^<>]+<\/\1>", flags=re.MULTILINE)
test_str = ("<b sdsd md sdsdds>a</b> \n"
"<b>adsa</b>\n"
"<b md>a</b>\n"
"<b md>sdasdas</b>\n"
"<b md class =\"sd\">aaa</b> <b md>aaa</b> <b md>a</b>\n"
"<b ac md>a</b>**DENEME** **DENEME**\n\n"
"<b md>sd <b md>sd</b></b>\n\n"
"<b md>(boş olmasın)</b>\n"
"<b md class =\"md\" id=\"1\">aaa</b> <b md>aaa</b> <b md>a</b>\n"
"<b md class =\"test sd md test\">aaa</b> <b md>aaa</b> <b md>a</b>\n\n"
"<b class=\"...blah md blah...\">(expression)</b>\n\n"
"<b class=\"... md ...\"></b> not match because tag is empty\n"
"<i class=\"...\"></i> not match because class attribute not include md\n"
"<span class=\"...md...\">ANYTHING</span> match\n"
"<b class=\"... md ...\"> </b>\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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