当前位置: 代码迷 >> Java相关 >> 对于arp -a 命令中,小弟我怎么去写正则表达式去获得ip和mac地址这两列
  详细解决方案

对于arp -a 命令中,小弟我怎么去写正则表达式去获得ip和mac地址这两列

热度:162   发布时间:2016-04-22 21:33:01.0
对于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));
}