# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<style>[\s\S]*<\/style>"
test_str = ("<!--\n"
" * @Descripttion: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE\n"
" * @version: April 2021 (version 1.56)\n"
" * @Author: ZhangKe\n"
" * @Date: 2022-04-15 11:12:09\n"
" * @LastEditors: ZhangKe\n"
" * @LastEditTime: 2022-04-15 11:20:25\n"
" * @FilePath: \\19_Node.js\\13_clocl时钟案例\\index.html\n"
"-->\n"
"<!DOCTYPE html>\n"
"<html lang=\"en\">\n\n"
"<head>\n"
" <meta charset=\"UTF-8\">\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
" <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n"
" <title>index首页</title>\n"
" <style>\n"
" html,\n"
" body {\n"
" margin: 0;\n"
" padding: 0;\n"
" height: 100%;\n"
" background-image: linear-gradient(to bottom right, red, gold);\n"
" }\n\n"
" .box {\n"
" width: 400px;\n"
" height: 250px;\n"
" background-color: rgba(255, 255, 255, 0.6);\n"
" border-radius: 6px;\n"
" position: absolute;\n"
" left: 50%;\n"
" top: 40%;\n"
" transform: translate(-50%, -50%);\n"
" box-shadow: 1px 1px 10px #fff;\n"
" text-shadow: 0px 1px 30px white;\n\n"
" display: flex;\n"
" justify-content: space-around;\n"
" align-items: center;\n"
" font-size: 70px;\n"
" user-select: none;\n"
" padding: 0 20px;\n\n"
" /* 盒子投影 */\n"
" -webkit-box-reflect: below 0px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0%, transparent), to(rgba(250, 250, 250, .2)));\n"
" }\n"
" </style>\n"
"</head>\n\n"
"<body>\n"
" <div class=\"box\">\n"
" <div id=\"HH\">00</div>\n"
" <div>:</div>\n"
" <div id=\"mm\">00</div>\n"
" <div>:</div>\n"
" <div id=\"ss\">00</div>\n"
" </div>\n\n"
" <script>\n"
" window.addEventListener('load', function (evt) {\n"
" // 定时器,每隔 1 秒执行 1 次\n"
" setInterval(() => {\n"
" var dt = new Date()\n"
" var HH = dt.getHours()\n"
" var mm = dt.getMinutes()\n"
" var ss = dt.getSeconds()\n\n"
" // 为页面上的元素赋值\n"
" document.querySelector('#HH').innerHTML = padZero(HH)\n"
" document.querySelector('#mm').innerHTML = padZero(mm)\n"
" document.querySelector('#ss').innerHTML = padZero(ss)\n"
" }, 1000)\n"
" });\n\n"
" // 补零函数\n"
" function padZero(n) {\n"
" return n > 9 ? n : '0' + n\n"
" }\n"
" </script>\n"
"</body>\n\n"
"</html>")
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