Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56382 > unrolled thread

Re: Re for Apache log file format

Started byAndreas Perstinger <andipersti@gmail.com>
First post2013-10-08 12:23 +0200
Last post2013-10-08 12:23 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Re for Apache log file format Andreas Perstinger <andipersti@gmail.com> - 2013-10-08 12:23 +0200

#56382 — Re: Re for Apache log file format

FromAndreas Perstinger <andipersti@gmail.com>
Date2013-10-08 12:23 +0200
SubjectRe: Re for Apache log file format
Message-ID<mailman.846.1381227820.18130.python-list@python.org>
On 08.10.2013 08:33, Sam Giraffe wrote:
> #this is a single line
> string = '192.168.122.3 - - [29/Sep/2013:03:52:33 -0700] "GET / HTTP/1.0"
> 302 276 "-" "check_http/v1.4.16 (nagios-plugins 1.4.16)"'
>
> #trying to break up the pattern match for easy to read code
> pattern = re.compile(r'(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+'
>                       r'(?P<ident>\-)\s+'
>                       r'(?P<username>\-)\s+'
>                       r'(?P<TZ>\[(.*?)\])\s+'
>                       r'(?P<url>\"(.*?)\")\s+'
>                       r'(?P<httpcode>\d{3})\s+'
>                       r'(?P<size>\d+)\s+'
>                       r'(?P<referrer>\"\")\s+'
>                       r'(?P<agent>\((.*?)\))')

[SNIP]

> The python interpreter is skipping to the 'math = re.search' and then the
> 'if' statement right after it looks at the <ip>, instead of moving onto
> <ident> and so on.

I'm not sure if I understand your problem, but your regex pattern only 
matches up to the size. When you look for the referrer, the pattern 
expects two quotes but in your string you have "-" (quote, dash, quote). 
Thus there is no match (i.e. "match" is None) and the if-statement will 
print "not found".

Bye, Andreas

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web