用于解析java中键值对中字符串的正则表达式

时间:2011-10-03 12:36:44

标签: java

我有这个字符串:

"{ '_id' : ObjectId('4e85ba250364e5a1857ba2e4'), 
   'message' : '<user=animesh@strumsoft.com>, <action=create-flock>, 
      params=[<title=[smile.animesh@gmail.com, ram@strumsoft.com], 
      attendees=immediate, flockType=immediate, duration=30]>' }";

我试过跟着正则表达式:

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

private static String REGEX2Final = "<(.*)>"; 
申请上面两个正则表达式后,最后出来是

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

但我想要按键/值格式的O / P,如

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

怎么做?

2 个答案:

答案 0 :(得分:0)

如果你有这个字符串

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

然后为什么不尝试这样做..

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);

答案 1 :(得分:0)

您可以为每一行使用以下代码:

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