日期:2014-05-19  浏览次数:20643 次

用正则表达式分解如下字符串,取出每项值
字符串如下:
13/January/12, 15:04:39:Send Message from UserId CN=test01
/O=citicsqas to UserId CN=test02/O=citicsqas msgLen 94 msg: <span style="font-size:9pt;font-family:宋体;color:#000000;" class="left">asdfasdfadsf</span> 


1.得到时间
2.得到发信人ID(Send Message from UserId)
3.得到收信人ID(to UserId)
4.得到内容(msg)

------解决方案--------------------
for example

Java code
String str = ...; //LZ的字符串
String[] sa = str.replaceAll("(.*?):Send .*? from (.*?)\\s+.*? to (.*?)\\s+.*? msg:\\s*(.*)", "$1|$2|$3|$4").split("[|]"); //提取相应的信息,并按自己规定的字符分割
for (String s : sa) {
    System.out.println(s);
}