我有一个如下所示的字符串,想根据条件拆分它。
|RECEIVE|Low| eventId=139569 msg=W4N Alert :: Critical : Interface Utilization for GigabitEthernet0/1 90.0 % in=2442 out=0 categorySignificance=/Normal categoryBehavior=/Communicate/Query categoryDeviceGroup=/Application
分割后应该是这样的
|RECEIVE|Low|
eventId=139569
msg=W4N Alert :: Critical : Interface Utilization for GigabitEthernet0/1 90.0 %
in=2442
out=0
categorySignificance=/Normal
categoryBehavior=/Communicate/Query
categoryDeviceGroup=/Application
条件是识别key=
之前的空格
最佳答案
您可以使用此正则表达式进行拆分(?=\s\w+=)
String str = "|RECEIVE|Low| ... p=/Application";
String[] spl = str.split("(?=\\s\\w+=)");
输出
|RECEIVE|Low|
eventId=139569
msg=W4N Alert :: Critical : Interface Utilization for GigabitEthernet0/1 90.0 %
in=2442
out=0
categorySignificance=/Normal
categoryBehavior=/Communicate/Query
categoryDeviceGroup=/Application
关于java正则表达式用于分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47131988/