我正在尝试区分两种不同类型的字符串,即IP地址和DNS地址。我在分割它时遇到了困难。我的初始想法是:
String stringIP = "123.345.12.1234";
String stringDNS = "iam.adns234.address.com";
if(!Pattern.matches("^[a-zA-Z0-9.]*$",stringDNS)){
//I only want to get IP type strings here, so I am trying to separate out anything containing alpha characters. `stringDNS` should not be allowed into the if statement.
}
stringIP
是无效的,因为它在最后一组中有四个数字。 - Sergey Kalinichenko