1
我想用正则表达式在openvswitch.log上创建一个模板。我有openvswitch.log跟随文本;用正则表达式创建模板
2017-05-18T06:40:02.850Z|00010|ofproto_dpif|INFO|[email protected]: Datapath supports recirculation
2017-05-18T06:40:02.850Z|00011|ofproto_dpif|INFO|[email protected]: MPLS label stack length probed as 1
2017-05-18T06:40:02.850Z|00012|ofproto_dpif|INFO|[email protected]: Datapath supports truncate action
2017-05-18T06:40:02.850Z|00013|ofproto_dpif|INFO|[email protected]: Datapath supports unique flow ids
2017-05-18T06:40:02.850Z|00014|ofproto_dpif|INFO|[email protected]: Datapath supports ct_state
2017-05-18T06:40:02.850Z|00015|ofproto_dpif|INFO|[email protected]: Datapath supports ct_zone
2017-05-18T06:40:02.850Z|00016|ofproto_dpif|INFO|[email protected]: Datapath supports ct_mark
2017-05-18T06:40:02.850Z|00017|ofproto_dpif|INFO|[email protected]: Datapath supports ct_label
2017-05-18T06:40:02.850Z|00018|ofproto_dpif|INFO|[email protected]: Datapath supports ct_state_nat
2017-05-18T06:40:02.861Z|00001|ofproto_dpif_upcall(handler1)|INFO|received packet on unassociated datapath port 0
2017-05-18T06:40:02.861Z|00019|bridge|INFO|bridge s1: added interface s1-eth2 on port 2
2017-05-18T06:40:02.862Z|00020|bridge|INFO|bridge s1: added interface s1-eth1 on port 1
2017-05-18T06:40:02.862Z|00021|bridge|INFO|bridge s1: added interface s1-eth3 on port 3
2017-05-18T06:40:02.865Z|00022|bridge|INFO|bridge s1: added interface s1 on port 65534
2017-05-18T06:40:02.865Z|00023|bridge|INFO|bridge s2: added interface s2-eth3 on port 3
2017-05-18T06:40:02.869Z|00024|bridge|INFO|bridge s2: added interface s2-eth2 on port 2
2017-05-18T06:40:02.869Z|00025|bridge|INFO|bridge s2: added interface s2-eth1 on port 1
2017-05-18T06:40:02.873Z|00026|bridge|INFO|bridge s2: added interface s2 on port 65534
2017-05-18T06:40:02.873Z|00027|bridge|INFO|bridge s1: using datapath ID 0000000000000001
2017-05-18T06:40:02.873Z|00028|connmgr|INFO|s1: added service controller "punix:/var/run/openvswitch/s1.mgmt"
2017-05-18T06:40:02.873Z|00029|connmgr|INFO|s1: added service controller "ptcp:6654"
2017-05-18T06:40:02.873Z|00030|connmgr|INFO|s1: added primary controller "tcp:192.168.29.87:6633"
2017-05-18T06:40:02.873Z|00031|rconn|INFO|s1<->tcp:192.168.29.87:6633: connecting...
2017-05-18T06:40:02.877Z|00032|bridge|INFO|bridge s2: using datapath ID 0000000000000002
例如;
桥S1:添加接口S1-ETH2端口
我想搜索“桥...添加接口...端口... “ 如何使用正则表达式找到此模板?我将使用Java语言
我写了一个java代码,但没有找到结果
public static void main(String[] args) {
Pattern p1 = Pattern.compile("bridge (s.*?): added interface (s.*?) on port (\\d+)");
Matcher m = p1.matcher("bridge s1: added interface s1-eth2 on port 0");
String log_output = "";
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, " ");
}
m.appendTail(sb);
System.out.println(sb.toString());
}
有一个愉快的一天大家
它没有找到一个结果:( – can
你没有指定你想用正则表达式做什么,也不是你用什么语言检查更新。答案。 – zwer
我更新了问题谢谢你的提醒:) – can