//将ip地址进行自然顺序的排序
//ip=ip.replaceAll("0*(\\d{3})","$1");理解不了,为什么是0*,而不是0+
//System.out.println(addr.replaceAll("0*(\\d+)","$1"));//这个也不理解
String ip="192.168.1.254 102.49.67.9 10.10.10.10 2.2.2.2 8.109.90.30";
ip=ip.replaceAll("(\\d+)","00$1");
System.out.println(ip);
ip=ip.replaceAll("0*(\\d{3})","$1");
System.out.println(ip);
String[] addrs=ip.split(" +");
Arrays.sort(addrs);
for (String addr:addrs )
{
System.out.println(addr.replaceAll("0*(\\d+)","$1"));
}
|
|