import re
regex = re.compile(r"^(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*(?:<[^>]+>\s*)+<title>contador\s*de \s*acessos<\/title>.{0,1350}?\$caminho\s*=\s*\"contador\.txt.{0,150}?\$arquivo\s*=\s*fopen\(\$caminho.{0,150}?numero\s*de\s*visitas\s*fclose\(\$arquivo.{0,650}?<meta.{0,50}?url=['\"]contador\.php.{0,50}?\/html[[:punct:]\s]+$", flags=re.IGNORECASE | re.DOTALL)
test_str = ("<html>\n"
"<head>\n"
"<title>Contador de Acessos</title>\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><style type=\"text/css\">\n"
"<!--\n"
"body,td,th {\n"
" color: #FF0000;\n"
" font-family: Verdana;\n"
" font-size: 12px;\n"
"}\n"
"body {\n"
" background-color: #CCCCCC;\n"
"}\n"
".style1 {\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
"}\n"
".style2 {\n"
" font-size: 12px;\n"
" color: #FF0000;\n"
"}\n"
".style3 {\n"
" font-size: 15px;\n"
" color: #000000;\n"
"}\n"
".style4 {color: #000000}\n"
".style5 {font-size: 15px; font-weight: bold; color: #000000; }\n"
".style8 {font-size: 24px; font-weight: bold; }\n"
".style9 {color: #CCCCCC}\n"
".style11 {color: #FF0000}\n"
".style12 {color: #FFFFFF}\n"
".style15 {color: #FFFFFF; font-size: 20px; }\n"
"-->\n"
"</style><body link=\"#FF0000\" vlink=\"#FF0000\" alink=\"#FF0000\">\n"
"<center>\n"
" <table width=\"476\" border=\"0\">\n"
" <tr>\n"
" <td width=\"470\" bgcolor=\"#000000\"><div align=\"center\"><span class=\"style15\"> CONTADOR - <span class=\"style11\">BB</span></span> </div></td>\n"
" </tr>\n"
" </table>\n"
" <p><span class=\"style5\"> $$ CONTADOR DE ACESSOS $$ <br>\n"
" <br> \n"
" <span class=\"style2\">==========================================================</span><br>\n"
" </span><br>\n"
" <span class=\"style4\">VOCÊ POSSUI<span class=\"style9\">-</span> </span>\n"
" </h1>\n"
" <span class=\"style8\">\n"
" <?php\n"
" $caminho = \"contador.txt\";//nome do arquivo que vai guardar os visitantes\n"
" $arquivo = fopen($caminho, \"r\");//abre o arquivo\n"
" $total = fgets($arquivo,1024); //pega o numero de visitas\n"
" fclose($arquivo);//fecha o arquivo\n"
" $x = $total;\n"
" echo \"\" . $x;//mostra na tela o numero de visitantes\n"
"?>\n"
" </span> <span class=\"style4\"> CLIQUES.</span> <br>\n"
" <br>\n"
" <br>\n"
" <br>\n"
" <span class=\"style4\"><strong>OBS:</strong> A PÁGINA FICA ATUALIZANDO AUTOMATICAMENTE EM 60 SEGUNDOS. </span></p>\n"
" <table width=\"568\" border=\"0\">\n"
" <tr>\n"
" <td bgcolor=\"#000000\"><div align=\"center\"><span class=\"style12\">CONTADOR SPAM<span class=\"style11\"></span></span></div></td>\n"
" </tr>\n"
" </table>\n"
" <p><br>\n"
" </p>\n"
" <meta http-equiv='Refresh' content='60'; URL='contador.php'>\n"
"</center>\n"
"</body>\n"
"</head>\n"
"</html>")
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