简体   繁体   English

java正则表达式,用于拆分字符串

[英]java regular Expression for splitting a string

I have a string like below, want to split it based on a condition. 我有一个如下所示的字符串,想根据条件进行拆分。

|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

after the split it should look like this 拆分后,它应该看起来像这样

|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

the condition is identify the space before key= 条件是在key=之前确定空格

You can split using this regex (?=\\s\\w+=) 您可以使用此正则表达式(?=\\s\\w+=)进行拆分

String str = "|RECEIVE|Low| ... p=/Application";
String[] spl = str.split("(?=\\s\\w+=)");

Outputs 输出

|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

  • ideone demo ideone演示

  • regex demo 正则表达式演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM