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: 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; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; ':-)': 0.13; 'cheers!': 0.16; 'iterator': 0.16; 'mardi': 0.16; 'match:': 0.16; 'whitespace.': 0.16; 'martin': 0.16; 'fix': 0.17; 'tests': 0.18; 'keywords,': 0.22; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'cc:2**1': 0.24; 'tried': 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; 'thanks!': 0.26; 'cc:addr:gmail.com': 0.27; 'possibly': 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; 'thank': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'url:mail': 0.40; 'your': 0.60; 'from:no real name:2**0': 0.60; 'containing': 0.61; '!!!': 0.62; 'potentially': 0.66; 'everything.': 0.84 Newsgroups: comp.lang.python Date: Tue, 23 Oct 2012 16:51:11 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=184.163.195.226; posting-account=kRgbswoAAAArSAk0ZrC9Cg6cpvEz1ebu References: <0becd1f8-e760-49c1-88d6-1c11b49e203c@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 184.163.195.226 MIME-Version: 1.0 Subject: Re: regex function driving me nuts From: cyberdicks@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "MartinD." , 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 91 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351036276 news.xs4all.nl 6850 [2001:888:2000:d::a6]:41386 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31977 Stripping the line did it !!! Thank you very much to all !!!=20 Cheers! :-)=20 Martin=20 Le mardi 23 octobre 2012 16:36:44 UTC-4, Vlastimil Brom a =E9crit=A0: > 2012/10/23 MartinD.=20 >=20 > > Hi, >=20 > > >=20 > > I'm new to Python. >=20 > > Does someone has an idea what's wrong. I tried everything. The only re= gex that is tested is the last one in a whole list of regex in keywords.txt >=20 > > Thanks! >=20 > > Martin >=20 > > >=20 > > >=20 > > ######## >=20 > > def checkKeywords( str, lstKeywords ): >=20 > > >=20 > > for regex in lstKeywords: >=20 > > match =3D re.search(regex, str,re.IGNORECASE) >=20 > > # If-statement after search() tests if it succeeded >=20 > > if match: >=20 > > print match.group() ##just debugging >=20 > > return match.group() ## 'found! >=20 > > >=20 > > return >=20 > > >=20 > > ######### >=20 > > >=20 > > keywords1 =3D [line for line in open('keywords1.txt')] >=20 > > resultKeywords1 =3D checkKeywords("string_to_test",keywords1) >=20 > > print resultKeywords1 >=20 > > >=20 > > -- >=20 > > http://mail.python.org/mailman/listinfo/python-list >=20 >=20 >=20 > Hi, >=20 > just a wild guess, as I don't have access to containing the list of >=20 > potentially problematic regex patterns >=20 > does: >=20 > keywords1 =3D [line.strip() for line in open('keywords1.txt')] >=20 > possibly fix yout problem? >=20 > the lines of the file iterator also preserve newlines, which might not >=20 > be expected in your keywords, strip() removes (be default) any >=20 > starting and tryiling whitespace. >=20 >=20 >=20 > hth, >=20 > vbr