开发者

Regular expression for parsing string in key value pair in java

I have this string:

"{ '_id' : ObjectId('4e85ba250364e5a1857ba2e4'), 
   'message' : '<user=animesh@strumsoft.com>, <action=create-flock>, 
      params=[<title=[smile.animesh@gmail.com, ram@strumsoft.com], 
      attendees=immediate, flockType=i开发者_如何学运维mmediate, duration=30]>' }";

I tried following regex on it:

private static String REGEXFinal = "<(.*?)>";

private static String REGEX2Final = "<(.*)>"; 

after applying above two regex final out come is

user=a@a.com
action=create-flock
title=[a@a.com, b@b.com], attendees=immediate, flockType=immediate, duration=30]

but I want O/P in key / value format like

user  a@a.com 
action create-flock
title  [a@a.com, b@b.com], attendees=immediate, flockType=immediate, duration=30]

how to do this?


You can use the following code for each line:

line.replaceFirst("=", " ");


if you got this String

user=a@a.com
action=create-flock
title=[a@a.com, b@b.com], attendees=immediate, flockType=immediate, duration=30]

Then why not try to do this..

String str="user=a@a.com action=create-flock title=[a@a.com, b@b.com], attendees=immediate, flockType=immediate, duration=30]";
str = str.replaceAll("=", " ");
System.out.println(str);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜