我有一个要遍历的Apache日志列表,并将每个元素分成一个新列表。
例如
firebaseAuth.onAuthStateChanged.map((FirebaseUser user) {
//do something with the user to understand which of the MULTIPLE providers he/she is currently signed in/out with
});
但是,其中一个条目的最后一个元素(用户代理)没有引号
83.149.9.216 - - [17/May/2015:10:05:03 +0000] "GET /presentations/logstash-monitorama-2013/images/kibana-search.png HTTP/1.1" 200 203023 "http://semicomplete.com/presentations/logstash-monitorama-2013/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"
Iam当前正在使用此正则表达式,
46.118.127.106 - - [20/May/2015:12:05:17 +0000] "GET /scripts/grok-py-test/configlib.py HTTP/1.1" 200 235 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html
但是,我得到一个错误
'NoneType'对象没有属性'groups'
该错误发生在没有结尾引号的行。如何更改我的正则表达式,以便它接受带或不带引号的用户代理?
答案 0 :(得分:0)
您可以在没有双引号的情况下添加双引号。
fileStr += '' if fileStr.endswith('"') else '"'
apacheTup = re.match( ....