Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56382
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andipersti@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.04; 'interpreter': 0.05; 'matches': 0.07; 'received:192.168.178': 0.07; 'subject:file': 0.07; 'string': 0.09; 'none)': 0.09; 'python': 0.11; '"-"': 0.16; '#this': 0.16; 'andreas': 0.16; 'bye,': 0.16; 'expects': 0.16; 'received:192.168.178.20': 0.16; 'skipping': 0.16; 'subject:Apache': 0.16; 'subject:format': 0.16; 'subject:log': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:User- Agent:1': 0.23; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'thus': 0.29; 'statement': 0.30; "i'm": 0.30; 'code': 0.31; "skip:' 10": 0.31; 'quotes': 0.31; '(i.e.': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'two': 0.37; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'moving': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'easy': 0.60; 'break': 0.61; 'size.': 0.65; 'sam': 0.68; '"not': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=5gVwDZOOOYKWGgYQ0qfUFbLaPwojLLzy52nQ/QaCY3k=; b=JPpI0lsrfw47gjpI5fvFaBpVa9Gm4MF4horUc1HpVCY/v8jMkDIMS1m1t+ihLKGXeV itkF7hTbpXu/byBmFYfzjXuEEPxXi+o9k4tn1CNrMxGvzXbmdO4hmenqpThlSkCVWkSh IKtQIWPFXCI69IqtwwAm+PL+G6YQMDH5nvtapDl/NS8wYIFZkU4D+gZj3/ZHAOBbMzLd DA8OiHU3pOK61AunQKFDE6vyOVr+it/JQP3vtBlUSWm+yblsmLodNZ82DnVjDTDDqN7Q rahIEu4E6vaMyNs3jQS/o+ZYbvUDbz+3nm/a+5dQC3VBjEIs6AEyQImmeV9aaXemttzN vaaQ== |
| X-Received | by 10.205.105.73 with SMTP id dp9mr701212bkc.33.1381227812664; Tue, 08 Oct 2013 03:23:32 -0700 (PDT) |
| Date | Tue, 08 Oct 2013 12:23:20 +0200 |
| From | Andreas Perstinger <andipersti@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Re for Apache log file format |
| References | <CAC97zZ_8dw2-3=7DAmECx89po_aQvHHsqqQYP7RTBaig5UVKZQ@mail.gmail.com> |
| In-Reply-To | <CAC97zZ_8dw2-3=7DAmECx89po_aQvHHsqqQYP7RTBaig5UVKZQ@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.846.1381227820.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1381227820 news.xs4all.nl 15921 [2001:888:2000:d::a6]:41961 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:56382 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Re for Apache log file format Andreas Perstinger <andipersti@gmail.com> - 2013-10-08 12:23 +0200
csiph-web