简体   繁体   English

Log Parser Lizard(MS Log Parser)忽略正则表达式

[英]Log Parser Lizard (MS Log Parser) Ignore Regex

first question so be gentle. 第一个问题要这样温柔。

I am a regex padawan. 我是正则表达式padawan。 I've only dabbled lightly. 我只是轻轻地涉猎。 I am experimenting with Log Parser Lizard by LizardLabs. 我正在使用LizardLabs的Log Parser Lizard进行实验。 I am writing an XML that the application uses MS Log Parser to apply regex to a log file to return the results in a pretty GUI. 我正在编写XML,该应用程序使用MS Log Parser将正则表达式应用于日志文件,以在漂亮的GUI中返回结果。 The XML contains tags which you define as fields, so forgive the messy code, but it's how it wants it... XML包含您定义为字段的标记,因此可以原谅凌乱的代码,但这就是它想要的方式...

<regex>\s{1,}(?&lt;PID&gt;(.*))\((?&lt;TID&gt;(.*))\)\s{1,}(?&lt;DATE&gt;(\d{2}\/\d{2}\/\d{4}))\s{1,}(?&lt;TIME&gt;(\d{2}:\d{2}:\d{2}))\s{1,}(?&lt;CLASS&gt;([A-Z][^\s]{1,}))\s{1,}(?&lt;TYPE&gt;(.{1}))\s{1,}(?&lt;MESSAGE&gt;(.{1,})).*</regex>
  <fields>
  <field name="PID" type="String" />
  <field name="TID" type="String" /> 
  <field name="DATE" type="String" />
  <field name="TIME" type="String" />
  <field name="CLASS" type="String" />
  <field name="TYPE" type="String" />
  <field name="MESSAGE" type="String" />
</fields>

Sample lines: 样例行:

3840( 5516) 03/15/2015 00:10:04 JS I Starting Incident Deadline Update Schedule 3840(5516)03/15/2015 00:10:04 JS I开始事件截止日期更新时间表

3840( 5516) 03/15/2015 00:10:04 JS I No records to be updated 3840(5516)03/15/2015 00:10:04 JS I无记录可更新

3648( 5444) 03/15/2015 01:00:07 JGroups version: 2.6.15.GA 3648(5444)03/15/2015 01:00:07 JGroups版本:2.6.15.GA

The regex correctly grabs the first two lines and parses it nicely, but the third line fails (obviously, because it's not the same format). 正则表达式正确地抓住了前两行并很好地解析了它,但是第三行失败了(显然,因为它的格式不同)。

The question: How do I use (?!JGroups) or [^JGroups] to make the regex properly ignore the JGroups line? 问题:如何使用(?!JGroups)或[^ JGroups]使正则表达式正确忽略JGroups行?

I have tried the following; 我已经尝试了以下方法;

(?&lt;CLASS&gt;([^JGroups][A-Z][^\s]{1,}))
(?&lt;CLASS&gt;((?!JGroups([A-Z][^\s]{1,})))

Neither seem to make it ignore that line (and continue matching). 似乎都没有使它忽略该行(并继续匹配)。

What am I doing wrong? 我究竟做错了什么? To complicate it further, using plain regex (without running it through this application) seems to work properly with my second example. 为了进一步使其复杂化,使用普通的正则表达式(无需通过该应用程序运行它)似乎可以与我的第二个示例一起正常工作。 Is it a fault of the application not knowing how to do these "ignore" matches? 是应用程序不知道如何进行这些“忽略”匹配的错误吗?

There are a few odd things in your regex. 正则表达式中有一些奇怪的事情。

\\s{1,} It seems you want to use space as a delimiter but you are actually saying 1 or 0 spaces \\s{1,}似乎您想使用空格作为分隔符,但实际上是说1或0个空格

(?<CLASS>([AZ][^\\s]{1,})) The class is a single letter (eg 'J'), followed by 1 or 0 non-space characters? (?<CLASS>([AZ][^\\s]{1,}))该类是单个字母(例如'J'),后跟1或0个非空格字符?

I can't help you much more without the format of the log itself but it looks like it should be should like this: \\s*(?<PID>([^\\s]*))\\((?<TID>([^\\s]*))\\)\\s(?<DATE>(\\d{2}\\/\\d{2}\\/\\d{4}))\\s(?<TIME>(\\d{2}:\\d{2}:\\d{2}))\\s(?<CLASS>([^\\s]*))\\s(?<TYPE>([^\\s]*))\\s(?<MESSAGE>(.*)) 没有日志本身的格式,我无法为您提供更多帮助,但是看起来应该是这样的: \\s*(?<PID>([^\\s]*))\\((?<TID>([^\\s]*))\\)\\s(?<DATE>(\\d{2}\\/\\d{2}\\/\\d{4}))\\s(?<TIME>(\\d{2}:\\d{2}:\\d{2}))\\s(?<CLASS>([^\\s]*))\\s(?<TYPE>([^\\s]*))\\s(?<MESSAGE>(.*))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM