2 回答
TA贡献1864条经验 获得超2个赞
稍微逃避你应该是好的:
regex1 = "[0-9]+\|INFO\|MyHalfDuplexModem@[0-9]+:println\|ENERGY:";
^^ this was the problem
|
`- this is the fix
没有逃逸|是一种交替,有效地导致"[0-9]+|INFO|MyHalfDuplexModem@[0-9]+:println" OR "ENERGY:"
另请注意,它\|与[|]. 我更喜欢前者。
TA贡献1777条经验 获得超3个赞
我想,这一个抓住了你想要的。它不是在 Java 中,它是纯正则表达式。
ENERGY:\s(.*)
这是Java示例
public static void main(String[] args) {
Pattern p = Pattern.compile("ENERGY:\\s(.*)");
String st = "1562173405047|INFO|MyHalfDuplexModem@30:println|ENERGY: -s 1 -d 2 -b 288 -e 9.999788799994675071125 T {-s 1, -d 2 }\n" +
"1562173405552|INFO|MyHalfDuplexModem@43:println|ENERGY: -s 3 -d 2 -b 96 -e 9.999779196127731100294 R {-s 3, -d 2 }\n" +
"1562173406122|INFO|MyHalfDuplexModem@43:println|ENERGY: -s 1 -d 2 -b 288 -e 9.999764796127731100294 R {-s 1, -d 2 }\n" +
"1562173406194|INFO|MyHalfDuplexModem@43:println|ENERGY: -s 2 -d 1 -b 96 -e 9.999759995924876667052 T {-s 2, -d 1 }";
Matcher mt = p.matcher(st);
while (mt.find()) {
String group = mt.group(1);
System.out.println(group);
}
}
输出:
-s 1 -d 2 -b 288 -e 9.999788799994675071125 T {-s 1, -d 2 }
-s 3 -d 2 -b 96 -e 9.999779196127731100294 R {-s 3, -d 2 }
-s 1 -d 2 -b 288 -e 9.999764796127731100294 R {-s 1, -d 2 }
-s 2 -d 1 -b 96 -e 9.999759995924876667052 T {-s 2, -d 1 }
添加回答
举报