import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<script>[\\s\\S]*<\\/script>";
final String string = "<!--\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>";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html