1

例子:

[Fri Oct 18 17:39:11 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:39:38 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:39:44 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/mariapiacasa.com.br/app/etc/local.xml
[Fri Oct 18 17:42:41 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:47:33 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:47:49 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:47:58 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:50:02 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 17:59:37 2013] [error] [client x.x.x.x] client denied by server configuration: /home/client/client.com.br/app/etc/local.xml
[Fri Oct 18 19:05:34 2013] [error] [client x.x.x.x] File does not exist: /home/client/client.com.br/skin/frontend/default/MAG080138

在这个例子中,我不想被服务器配置拒绝的消息客户端监控行: /home/client/client.com.br/app/etc/local.xml。其他一切都应该受到监控。我知道如何使用以下正则表达式找到我不想出现的内容:

.*client denied by server configuration:.*\/app\/etc\/local\.xml$

在上面的例子中应该只监控一行:

[Fri Oct 18 19:05:34 2013] [error] [client x.x.x.x] File does not exist: /home/client/client.com.br/skin/frontend/default/MAG080138
4

1 回答 1

0

在正则表达式中,当且仅当它后面没有其他内容时,您可以使用负前瞻,使用(?!<regexpression>), 来匹配某些内容。

所以为了匹配任何不包含表达式的行:

client denied by server configuration:.*\/app\/etc\/local\.xml

您可以通过这种方式使用负前瞻:

 ^(?:.(?!client denied by server configuration:.*\/app\/etc\/local\.xml))*$
   ^ non capture group
     ^ any character
      ^not followed by 
         ^ your regex

(看到它在行动

但是,这个正则表达式会表现得更好:

^.* \[client x.x.x.x\] (?!client denied by server configuration:.*\/app\/etc\/local\.xml).*$

(看到它在行动

因为负前瞻只执行一次,而不是在每个字符匹配之后执行。

希望这可以帮助。

祝你好运!

于 2013-10-19T11:30:33.537 回答