擅长:python、mysql、java
<p>您可以使用:</p>
<pre><code>import re
lines = ['[16/Aug/2016:06:13:25 -0400] "GET /file/ HTTP/1.1" 302 random stuff ignore', '[16/Aug/2016:06:13:25 -0400] "" 400 random stuff ignore']
rx = re.compile(r'''
"[^"]*" # ", followed by anything not a " and a "
\ # a space
\d+ # at least one digit
''', re.VERBOSE)
matches = [m.group(0) \
for line in lines \
for m in rx.finditer(line)]
print(matches)
# ['"GET /file/ HTTP/1.1" 302', '"" 400']
</code></pre>
<p/><hr/>
见<a href="http://ideone.com/1Zjvok" rel="nofollow"><strong>a demo on ideone.com</strong></a>。