【发布时间】:2013-10-06 18:59:48
【问题描述】:
我希望下面的代码会找到所有可用的模式标记。我解析了 shell 命令iwlist wlp3s0 scanning,所以总是有不止一个访问点(重复模式)。我需要以某种方式解析它们。
Scanner s = new Scanner(commandOutput);
String pattern = ".*?Address: (\\S*) .*?Channel:(\\d*) .*?Frequency:(\\S*) .*?Quality=(\\d*)/(\\d*) .*?Signal level=-(\\d*)";
//s.findInLine(pattern);
while(true){
s.findInLine(pattern);
MatchResult result = s.match();
for (int i = 1; i <= result.groupCount(); i++) {
System.out.println(result.group(i));
}
}
但它会抛出这个异常:java.lang.IllegalStateException。
如何在遍历循环而不是 while(true) 和异常时检查它是否有更多匹配项?
【问题讨论】:
-
你为什么需要那个?