日期:2014-05-20  浏览次数:20660 次

对于arp -a 命令中,我如何去写正则表达式去获得ip和mac地址这两列
如图所示,我只需要前两列,即ip和mac
正则表达式 java

------解决方案--------------------
每一行匹配一次。

String str="111.111.111.111 ab-bb-bb-bb-bb-bb fefe";
String regex=".*?(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*?(\\w{2}-\\w{2}-\\w{2}-\\w{2}-\\w{2}-\\w{2})";
// String regex="(\\d){1}";
Matcher m = Pattern.compile(regex).matcher(str);

while(m.find()){
System.out.print(m.group(1)+",");
System.out.println(m.group(2));
}