import re
regex = re.compile(r"<center>(.|\n)*?<\/center>")
test_str = ("</head>\n\n"
"<body style=\"background-color:#9b9b9b;\">\n"
"**<center>\n"
"<table width=\"580\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class =\"responsive-table\" style=\"background-color:#3e5b3e;border:solid thin #3e5b3e;\" >\n"
" <tbody>\n"
" <tr>\n"
" <td background=\"http://app.randomsite.com/js/ckfinder/userfiles//images/banner.jpg\" style=\"padding-top:20px;padding-right:20px;padding-left:20px;\" class=\"hideForMobile\"><h1 style=\"font-family:Arial, Helvetica, sans-serif;font-size:20px;font-weight:bold;text-align:right;color:#eee;vertical-align:bottom;text-decoration:none;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;\" >some message</h1></td>\n"
" </tr>\n"
" <tr>\n"
"</center>**\n"
" <!---Start of Banner Image--->\n"
" <td><a href=\"{{Custom1}}\" style=\"color:inherit;text-decoration:none;\" ><img src=\"http://app.clientcommand.com/js/ckfinder/userfiles//images/top-dollar-ford-banner.jpg\" alt=\"\" class=\"table.responsiveImage\" style=\"display:block;width:100%;border-style:none;\" /></a></td>\n"
" <!---End of Banner Image--->\n"
" </tr>\n"
" <tr>\n\n"
"**<center>\n"
"<table width=\"580\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class =\"responsive-table\" style=\"background-color:#3e5b3e;border:solid thin #3e5b3e;\" >\n"
" <tbody>\n"
" <tr>\n"
" <td background=\"http://app.randomsite.com/js/ckfinder/userfiles//images/banner.jpg\" style=\"padding-top:20px;padding-right:20px;padding-left:20px;\" class=\"hideForMobile\"><h1 style=\"font-family:Arial, Helvetica, sans-serif;font-size:20px;font-weight:bold;text-align:right;color:#eee;vertical-align:bottom;text-decoration:none;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;\" >some message</h1></td>\n"
" </tr>\n"
" <tr>\n"
"</center>**")
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