JAVA正则表达式判断IP地址 以下代码对Ip做简单的匹配:
public static boolean isIpv4(String ipAddress) {
<span style="white-space:pre"> </span>String ip = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
<span style="white-space:pre"> </span>+"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
<span style="white-space:pre"> </span>+"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
<span style="white-space:pre"> </span>+"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
<span style="white-space:pre"> </span>Matcher matcher = <span style="font-family: Arial;">Pattern.compile(ip)</span><span style="font-family: Arial;">.matcher(ipAddress);</span>
<span style="white-space:pre"> </span>return matcher.matches();
}
本文提供了一个使用Java正则表达式来验证IPv4地址有效性的简单方法。通过提供的代码示例,可以快速了解如何检查一个字符串是否符合标准IPv4地址格式。
555

被折叠的 条评论
为什么被折叠?



