```Python
# 注意这个 pattern 的最后一部分是 req_id
pattern = r'(?P<remote_addr>.*?)\ \-\ (?P<remote_user>.*?)\ \[(?P<time_local>.*?)\]\ "(?P<request>.*?)"\ (?P<status>.*?)\ (?P<body_bytes_sent>.*?)\ "(?P<http_referer>.*?)"\ "(?P<http_user_agent>.*?)"\ (?P<req_id>.*?)'
regex = re.compile(pattern)
print("---- regex:", regex)
```
print 出来的结果:
> ---- regex: re.compile('(?P<remote_addr>.*?)\\ \\-\\ (?P<remote_user>.*?)\\ \\[(?P<time_local>.*?)\\]\\ "(?P<request>.*?)"\\ (?P<status>.*?)\\ (?P<body_bytes_sent>.*?)\\ "(?P<http_referer>.*?)"\\ "(?P<http_user_agent>.*?)"\)
缺少了最后一部分`req_id`,到了`http_user_agent`就结束了。。。
一直想不通为什么,特来求助 |
|