2015-04-07 174 views
-1

任何人都可以帮我写一个特定日志格式的正则表达式吗?以下是我为它编写的示例日志和正则表达式,但它不起作用。日志格式的正则表达式

Log : 64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET 
/twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables 
HTTP/1.1" 401 12846 

我想正则表达式为:"%h - - %t \"%r\" %>s %b"

+2

请问你能指定一下你想在这个字符串中匹配什么吗? –

+0

你能比*“它不工作”*更具体吗?你如何应用正则表达式,输出是什么,以及你期望的是什么? – jonrsharpe

回答

0

每个日志可能是存储在单独的一行。尝试简单:

"Log : .* \n" 

或指定您想要匹配和检索的内容。

0

你可以尝试这样的:Log\s*:\s*([\d.]+)[\s-]+\[([\d\/A-Za-z: -]+)\]\s+"([A-Z]+)\s+(.+?)"\s+([\s\d]+)

这将匹配以下分组:

  1. 64.242.88.10
  2. 07 /三月/ 2004:16:05:49 -0800
  3. GET
  4. /TWiki的/ bin中/编辑/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables HTTP/1.1

有一个示例可用here