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


Groups > comp.lang.python > #31956

Re: regex function driving me nuts

References <0becd1f8-e760-49c1-88d6-1c11b49e203c@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-10-23 14:32 -0600
Subject Re: regex function driving me nuts
Newsgroups comp.lang.python
Message-ID <mailman.2689.1351024383.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Oct 23, 2012 at 1:51 PM, MartinD. <cyberdicks@gmail.com> wrote:
> 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

How do you know that it's the only one being tested?  Your debugging
statement only prints one that actually matches, not each one that is
tried.

> keywords1 = [line for line in open('keywords1.txt')]

Note that each "keyword" will including the trailing newline, if any.
This is probably why you are only seeing the last keyword match:
because it is the only one without a trailing newline.

To remove the newlines, call the str.strip or str.rstrip method on
each line, or use the str.splitlines method to get the keywords:

keywords1 = open('keywords1.txt').read().splitlines()

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