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


Groups > comp.lang.python > #31957

Re: regex function driving me nuts

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'patterns': 0.04; 'debugging': 0.05; 'removes': 0.05; 'problem?': 0.07; 'default)': 0.09; 'preserve': 0.09; 'str,': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'iterator': 0.16; 'match:': 0.16; 'whitespace.': 0.16; 'martin': 0.16; 'fix': 0.17; 'tests': 0.18; 'keywords,': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; 'thanks!': 0.26; 'possibly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'url:mailman': 0.29; "i'm": 0.29; 'url:python': 0.32; 'file': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'expected': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'header:Received:5': 0.40; 'url:mail': 0.40; 'your': 0.60; 'containing': 0.61; 'potentially': 0.66; 'everything.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=H0SpdbjzNSR/0NmKOVE6EWg3zsEevQ7+E473vG/kRqQ=; b=sH5McEYdiNEjSgGN7TkOFyEFPSQlWiDr2oWA12j8br4yeuL/BfTtw0NPda++IcE913 k72ObLYZdBVClByurGlzYi1S0JfFJ4TD4Nh52cobdaO3r7lHEn7yQrFHwB8Ncuh7yEFW 41/ZYDx1qiBuhLfpgzyqcwcUHReTxfst57TgaWk3o+A+q4xZR2VPxBpnGyIp2ShDPXe0 fyk1iA7/38sllEBb4kQNe2Uh/jk3c+IxIf3zK0vLzSZdVNxmBNFYRnE0iPGYY7Nlxm51 so/dT26Rv3VwK2k1M2cNAkwda6WXvwBPq4JEaW2wWU4NBcjsxFHkpCTLSRJrWpAJE1XT wRoQ==
MIME-Version 1.0
In-Reply-To <0becd1f8-e760-49c1-88d6-1c11b49e203c@googlegroups.com>
References <0becd1f8-e760-49c1-88d6-1c11b49e203c@googlegroups.com>
Date Tue, 23 Oct 2012 22:36:40 +0200
Subject Re: regex function driving me nuts
From Vlastimil Brom <vlastimil.brom@gmail.com>
To "MartinD." <cyberdicks@gmail.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>
Newsgroups comp.lang.python
Message-ID <mailman.2690.1351024603.27098.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351024603 news.xs4all.nl 6882 [2001:888:2000:d::a6]:35784
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31957

Show key headers only | View raw


2012/10/23 MartinD. <cyberdicks@gmail.com>:
> Hi,
>
> I'm new to Python.
> Does someone has an idea what's wrong.  I tried everything. The only regex that is tested is the last one in a whole list of regex in keywords.txt
> Thanks!
> Martin
>
>
> ########
> def checkKeywords( str, lstKeywords ):
>
>         for regex in lstKeywords:
>                 match = re.search(regex, str,re.IGNORECASE)
>                 # If-statement after search() tests if it succeeded
>                 if match:
>                         print match.group() ##just debugging
>                         return match.group() ## 'found!
>
>         return
>
> #########
>
> keywords1 = [line for line in open('keywords1.txt')]
> resultKeywords1 = checkKeywords("string_to_test",keywords1)
> print resultKeywords1
>
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
just a wild guess, as I don't have access to  containing the list of
potentially problematic regex patterns
does:
keywords1 = [line.strip() for line in open('keywords1.txt')]
possibly fix yout problem?
the lines of the file iterator also preserve newlines, which might not
be expected in your keywords, strip() removes (be default) any
starting and tryiling whitespace.

hth,
  vbr

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


Thread

regex function driving me nuts "MartinD." <cyberdicks@gmail.com> - 2012-10-23 12:51 -0700
  RE: regex function driving me nuts "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-23 20:29 +0000
  Re: regex function driving me nuts Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-23 14:32 -0600
  Re: regex function driving me nuts Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-10-23 22:36 +0200
    Re: regex function driving me nuts cyberdicks@gmail.com - 2012-10-23 16:51 -0700
    Re: regex function driving me nuts cyberdicks@gmail.com - 2012-10-23 16:51 -0700
  Re: regex function driving me nuts Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-24 01:27 -0400

csiph-web