import re
regex = re.compile(r"<p>(.*)<\/p>", flags=re.DOTALL)
test_str = ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n"
" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
"<head>\n"
"xxxx\n"
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
" <meta name=\"calibre:cover\" content=\"true\"/>\n"
" <title>Cover</title>\n"
" <style type=\"text/css\" title=\"override_css\">\n"
" @page {padding: 0pt; margin:0pt}\n"
" body { text-align: center; padding:0pt; margin: 0pt; }\n"
" </style>\n"
" </head>\n"
" <body>\n"
" <div>\n"
" <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" width=\"100%\" height=\"100%\" viewBox=\"0 0 566 734\" preserveAspectRatio=\"none\">\n"
"<p>\n"
"1\n"
"2\n"
"3\n"
"4\n"
"5\n"
"</p>\n\n"
" <image width=\"566\" height=\"734\" xlink:href=\"../Images/cover.jpeg\"/>\n"
"yyyy\n"
" </svg>\n"
" </div>\n"
"</body>\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