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


Groups > comp.lang.python > #34761

Re: Using regexes versus "in" membership test?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news0.firedrake.org!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <victorhooi@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'parsing': 0.07; 'subject:test': 0.07; 'matched': 0.09; 'pointers': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; "wouldn't": 0.11; 'dec': 0.15; '"in"': 0.16; 'discarded': 0.16; 'phase,': 0.16; 'regex,': 0.16; 'subject:versus': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'instance,': 0.17; 'module,': 0.17; 'thu,': 0.17; 'trying': 0.21; 'parse': 0.22; 'strip': 0.22; "i'd": 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'possibly': 0.27; 'possible,': 0.27; 'lines': 0.28; 'all.': 0.28; 'chris': 0.28; 'post': 0.28; 'steven': 0.29; "i'm": 0.29; 'thursday,': 0.30; 'function': 0.30; 'error': 0.30; 'figure': 0.30; 'december': 0.32; 'info': 0.32; 'presence': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'false': 0.35; 'said,': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'subject:" ': 0.36; 'test': 0.36; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'first': 0.61; 'more': 0.63; 'percent': 0.65; 'message"': 0.84; 'quicker': 0.84; 'subject:Using': 0.84; 'victor': 0.84; 'subject:membership': 0.91
Newsgroups comp.lang.python
Date Wed, 12 Dec 2012 22:35:28 -0800 (PST)
In-Reply-To <mailman.822.1355379600.29569.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=202.147.46.147; posting-account=LMx4fAoAAAAL3v616YFvkt1ueXc1H63-
References <56f4fbf5-36e6-40d0-b832-e29f8a67190b@googlegroups.com> <50c92acd$0$29972$c3e8da3$5496439d@news.astraweb.com> <a56c17dc-271e-44c7-bc3f-246366383817@googlegroups.com> <mailman.822.1355379600.29569.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 202.147.46.147
MIME-Version 1.0
Subject Re: Using regexes versus "in" membership test?
From Victor Hooi <victorhooi@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.823.1355380538.29569.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355380538 news.xs4all.nl 6958 [2001:888:2000:d::a6]:45442
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34761

Show key headers only | View raw


Heya,

See my original first post =):

> Would I be substantially better off using a list of strings and using "in" against each line, then using a second pass of regex only on the matched lines? 

Based on what Steven said, and what I know about the logs in question, it's definitely better to do it that way.

However, I'd still like to fix up the regex, or fix any glaring issues with it as well.

Cheers,
Victor

On Thursday, 13 December 2012 17:19:57 UTC+11, Chris Angelico  wrote:
> On Thu, Dec 13, 2012 at 5:10 PM, Victor Hooi <victorhooi@gmail.com> wrote:
> 
> > Are there any other general pointers you might give for that regex? The lines I'm trying to match look something like this:
> 
> >
> 
> >     07:40:05.793627975 [Info  ] [SOME_MODULE] [SOME_FUNCTION] [SOME_OTHER_FLAG] [RequestTag=0 ErrorCode=3 ErrorText="some error message" ID=0:0x0000000000000000 Foo=1 Bar=5 Joe=5]
> 
> >
> 
> > Essentially, I'd want to strip out the timestamp, logging-level, module, function etc - and possibly the tag-value pairs?
> 
> 
> 
> If possible, can you do a simple test to find out whether or not you
> 
> want a line and then do more complex parsing to get the info you want
> 
> out of it? For instance, perhaps the presence of the word "ErrorCode"
> 
> is all you need to check - it wouldn't hurt if you have a few percent
> 
> of false positives that get discarded during the parse phase, it'll
> 
> still be quicker to do a single string-in-string check than a complex
> 
> regex to figure out if you even need to process the line at all.
> 
> 
> 
> ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Using regexes versus "in" membership test? Victor Hooi <victorhooi@gmail.com> - 2012-12-12 14:35 -0800
  Re: Using regexes versus "in" membership test? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-13 01:09 +0000
    Re: Using regexes versus "in" membership test? Victor Hooi <victorhooi@gmail.com> - 2012-12-12 22:10 -0800
      Re: Using regexes versus "in" membership test? Chris Angelico <rosuav@gmail.com> - 2012-12-13 17:19 +1100
        Re: Using regexes versus "in" membership test? Victor Hooi <victorhooi@gmail.com> - 2012-12-12 22:35 -0800
          Re: Using regexes versus "in" membership test? Chris Angelico <rosuav@gmail.com> - 2012-12-13 17:38 +1100
        Re: Using regexes versus "in" membership test? Victor Hooi <victorhooi@gmail.com> - 2012-12-12 22:35 -0800

csiph-web