I'm struggling with finding the right regex for parsing a string containing key/value pairs. The string should be split on space when not surrounded by double quotes.
Example string:
2013-10-26 15:16:38:011+0200 name="twitter-message" from_user="MyUser" in_reply_to="null" start_time="Sat Oct 26 15:16:21 CEST 2013" event_id="394090123278974976" text="Some text" retweet_count="1393"
Desired output should be
2013-10-26
15:16:38:011+0200
name="twitter-message"
from_user="MyUser"
in_reply_to="null"
start_time="Sat Oct 26 15:16:21 CEST 2013"
event_id="394090123278974976"
text="Some text"
retweet_count="1393"
I found this answer to get me near the desired result Regex for splitting a string using space when not surrounded by single or double quotes with regex :
Matcher m = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'").matcher(str);
while (m.find())
list.add(m.group());
This gives a list of:
2013-10-26
15:16:38:011+0200
name=
"twitter-message"
from_user=
"MyUser"
in_reply_to=
"null"
start_time=
"Sat Oct 26 15:16:21 CEST 2013"
event_id=
"394090123278974976"
text=
"Some text"
retweet_count=
"1393"
It splits on = sign so there is still something missing to get to the desired output.