我想从事件日志中的某些字符串中提取数据。所有事件字符串都以 [0r(1)2[000p[040qe1w3h162[020t*] 开头。遇到一个新的,它应该解析最后一个字符串集并获取一些数据。显示了一个示例事件。除了另一个事件的开始之外,还有几个事件将跟随自己,没有分隔符。
[0r(1)2[000p[040qe1w3h162[020t*881*11/11/2010*12:24*
*EVENT STARTED*
[020t 12:24:06 SMARTCARD ENTERED
11\11\10 12:24 10390011
123456789098765432 6598
INVALID TRANSACTION, PLEASE CONTACT
ADMIN FOR ADVICE
-----------------------------------
[020t 12:24:52 FILE STACKED
[020t 12:24:59 FILE PRESENTED 0,5,0,0
[020t 12:25:03 FILE TAKEN
11\11\10 12:25 10390011
123456789098765432 6599
WITHDRAW FILES10.00
[000p[040q(1 *6599*1*E*000050000,M-00,R-10200
-----------------------------------
[020t 12:25:34 SMARTCARD TAKEN
[020t 12:25:38 EVENT ENDED
我想将日期和时间提取为每个活动的一个变量。例如
Activity= EVENT STARTED
Activity time/date= 11/11/2010 12:24
Activity= SmartCard inserted
Activity time/date= 12:24:06
我想我已经编写了代码来使用下面列出的代码来识别事件的开始。
import java.util.regex.*;
public class Test
{
public static void main(String args[])
{
String line = "[0r(1)2[000p[040qe1w3h162[020t*882*11/11/2010*12:26*";
String[] parts = line.split("\\*");
String date = parts[2];
String time = parts[3];
System.out.println("date=" + date + ", time=" + time);
}
}
谢谢