fix: 正则表达式问题

This commit is contained in:
小熊
2025-07-20 10:27:57 +08:00
parent 2f445d9150
commit b8c44c9fe2

View File

@@ -70,11 +70,20 @@ public class RegexConstants {
* 域名、IPV4、IPV6
* </p>
*/
public static final String HTTP_HOST = """
^((?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}|
(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|
(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|
""";
public static final String HTTP_HOST =
"^(" +
// ① 域名
"(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z]{2,63}" +
"|" +
// ② IPv4
"(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)" +
"|" +
// ③ IPv68 组 1-4 位十六进制,用 : 分隔,支持压缩 0
"(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}" +
"|" +
// ④ IPv6 压缩形式(::
"(?:[0-9A-Fa-f]{1,4}:){0,6}::(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4}" +
")$";
private RegexConstants() {
}