Reputation: 115
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=
Upvotes: 2
Views: 80
Reputation: 59978
You can split using this regex (?=\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
Upvotes: 3