如何在像
这样的字符串中找到类似127.0.0.1
的IP地址
fdgdfgd127.0.0.1fhj
但当然它将是一个不同的IP地址
答案 0 :(得分:1)
String ip="raje127.0.0.1something";
String IPADDRESS_PATTERN =
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
public IPAddressValidator(){
pattern = Pattern.compile(IPADDRESS_PATTERN);
Matcher matcher = pattern.matcher(ip);
return matcher.matches();
}
答案 1 :(得分:0)