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();
}