0

我正在尝试匹配我在日志文件中看到的异常行。日志文件的格式为“[timestamp] threadid(8 位字母数字) applicationName(任意长度的字母数字字符) E(表示异常消息)”

因此,示例日志异常消息将是:

“[11/27/12 22:33:02:635 EST] 0000009a myApplication E” 任何东西都可以在 E 之后出现。

我无法使用 PHP preg_match 找到一个正则表达式来匹配它

任何帮助,将不胜感激。

干杯

4

2 回答 2

0

试试这个正则表达式(带捕获组):

/^\[\d+/\d+/\d+\s+\d+:\d+:\d+:\d+\s+\w+\]\s+\w{8}\s+\w+\s+E(.*)/
于 2013-03-18T23:14:18.477 回答
0

try the following:

'/^\[[^\]]+\]\s\w{8}\s[^\s]+\sE.*/m'

The trailing "m" ensures, that the wedge at the beginning matches the beginning of a line in your log.

This solution will of course only work, if all the log entries look pretty similar except for the "E". If there are log entries e.g. without timestamps, it might fail and you have to look for more detailed expressions like sputnick's.

于 2013-03-18T23:10:07.237 回答