-1

什么是仅从 nginx 日志中查找 URI 的完全匹配正则表达式(python)?

00.00.00.00 - - [23/Mar/2020:16:23:04 +0000] "GET /foo/bar/uri.js?id=123 HTTP/1.1" 200 19165 "https://nginx.com/foo/bar" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" "00.00.00.00" 0.000

00.00.00.00 - - [23/Mar/2020:16:23:04 +0000] "GET /foo/bar/uri HTTP/1.1" 200 19165 "https://nginx.com/foo/bar" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" "00.00.00.00" 0.000

00.00.00.00 - - [23/Mar/2020:16:23:04 +0000] "GET /foo/bar/uri.png HTTP/1.1" 200 19165 "https://nginx.com/foo/bar" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" "00.00.00.00" 0.000

完全匹配的正则表达式应该在下面给出

/foo/bar/uri.js?id=123
/foo/bar/uri
/foo/bar/uri.png

完全匹配正则表达式的示例:https ://regex101.com/r/kEOx1U/3

4

1 回答 1

0

匹配该 URI 的正则表达式如下(单击此处):

(?<=GET )([^ ]*)

显然,如果您不仅要匹配,还要提取,这意味着删除所有其余部分,您也可以匹配它(单击此处):

.*(?<=GET )([^ ]*).*

$1在替换中使用(在 Perl 中;如果您需要 Python,则使用\1)。

于 2020-03-27T21:08:04.633 回答