URI的完全匹配正则表达式

时间:2020-03-27 20:04:00

标签: regex nginx-log

什么是仅从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

1 个答案:

答案 0 :(得分:0)

与URI相匹配的正则表达式如下(click here):

1  QPrinter::toPage() const                                                                      
2 QtWebEngineCore::PrinterWorker::print()                                                
3  QtWebEngineCore::PrinterWorker::qt_static_metacall(QObject *, QMetaObject::Call, int, void * *)
4  QObject::event(QEvent *)                                                                        
5  QApplicationPrivate::notify_helper(QObject *, QEvent *)                                         
6  QApplication::notify(QObject *, QEvent *)                                                       
7  QCoreApplication::notifyInternal2(QObject *, QEvent *)                                         
8  QCoreApplicationPrivate::sendPostedEvents(QObject *, int, QThreadData *)                        
9  postEventSourceDispatch(_GSource *, int ( *)(void *), void *)                                   
10 g_main_context_dispatch                                                                         
11 ___lldb_unnamed_symbol354$$libglib-2.0.so.0                                                     
12 g_main_context_iteration                                                                        
13 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)                      
14 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)                                         
15 QThread::exec()                                                                                 
16 QThreadPrivate::start(void *)                                                                   
17 start_thread                                                                                    
18 __GI___clone                                                                                    

很显然,如果您不仅要匹配,而且要提取,这意味着删除所有其余部分,那么您也要匹配(click here):

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

并在替换中使用.*(?<=GET )([^ ]*).* (在Perl中;如果需要Python,则使用$1)。

相关问题