# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<tr[^>]*>[^<]*<td[^>]*>(?<No>[^<]*)<[^>]*>[^>]*>(?<ID_dist>[^<]*)<\/td>[^>]*>(?<Jmeno>[^<]*)<\/td>[^>]*>(?<Tel_Home>[^<]*)<\/td>[^>]*>(?<Tel_Buss>[^<]*)<\/td>[^>]*>(?<Tel_mob>[^<]*)<\/td>[^>]*>(?<Country>[^<]*)<\/td>[^>]*><a[^>]*>(?<Email>[^<]*)[^<]*<\/a>[^<]*<\/td>[^>]*>(?<Levels>[^<]*)<\/td>[^>]*>(?<Pozice>[^<]*)<\/td>[^>]*>(?<Sponzor_ID>[^<]*)<\/td>"
test_str = ("\n"
" <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
"<head>\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
"<title>PBC - Distributors to be Renewed List</title>\n"
"<meta name=\"description\" content=\"Lifestyles PBC is an on-line tool to help our Distributors manage their business and achieve their goals.\" />\n"
"<meta name=\"keywords\" content=\"Lifestyles, Lifestyles International, Personal Business Center, PBC\"/>\n"
"<link href=\"css/en.css\" rel=\"stylesheet\" type=\"text/css\" />\n"
"</head>\n"
"<body bgcolor=\"#EAF4D1\" leftmargin=\"0\" topmargin=\"3\" marginwidth=\"0\" marginheight=\"0\">\n"
"<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#999999\">\n"
" <tr> <td height=\"33\" colspan=\"11\" align=\"center\" bgcolor=\"#FFFFFF\"><h2 style=\"margin: 10px\">Distributors to be Renewed List</h2>\n"
" <p style=\"margin: 10px\">Month: Nov. 2017</p></td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#CCCCCC\"><strong>No.</strong></td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#CCCCCC\"><strong>ID</strong></td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#CCCCCC\"><strong>Name</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Home Phone</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Business Phone</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Cell Phone</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Country</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Email</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Levels</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Rank</strong></td>\n"
" <td align=\"center\" bgcolor=\"#CCCCCC\"><strong>Sponsor</strong></td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">1</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">98000204732</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">Pavel Kaleta</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">420 773512280</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Czech Republic</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"mailto:\"></a></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">19</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Distributor</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">80011630542</td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">2</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">98000229140</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">Ivana Bilkova</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">420 605934970</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Czech Republic</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"mailto:ifcabilkova@seznam.cz\">ifcabilkova@seznam.cz</a></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">20</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Distributor</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">98000142059</td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">3</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">98000229289</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">Martina Vitkovska</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">420 606629784</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Czech Republic</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"mailto:martinavitkovska@seznam.cz\">martinavitkovska@seznam.cz</a></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">18</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Distributor</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">13980242</td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">4</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">98000253035</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">Lenka Lovetinska</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">420 60598685</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">420 567223836</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Czech Republic</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"mailto:lovetinskal@seznam.cz\">lovetinskal@seznam.cz</a></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">20</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Distributor</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">98000142059</td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">5</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">98000253463</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">Filip Korda</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">421 902483141</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">421 948186144</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Slovak Republic</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"mailto:korda@sanusvita.sk\">korda@sanusvita.sk</a></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">20</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Distributor</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">80011633242</td>\n"
" </tr>\n"
" <tr>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">6</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">CZ-03-04277</td>\n"
" <td height=\"27\" align=\"center\" bgcolor=\"#FFFFFF\">Olga Kostomarova</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">420 603160599</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Czech Republic</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"mailto:\"></a></td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">19</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">Distributor</td>\n"
" <td align=\"center\" bgcolor=\"#FFFFFF\">80011630542</td>\n"
" </tr>\n"
" </table>\n"
"</body>\n"
"</html>\n"
"<script>window.focus()</script>\n")
matches = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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