2

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=

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

What's the inner parentheses for?
thank you @shmosel i was testing for that i don't make attention thank you very much i edit it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.