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


Groups > comp.lang.python > #73952

Why is regexp not working?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; '(all': 0.07; 'none,': 0.07; 'matched': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'terminated': 0.09; 'def': 0.12; '[none,': 0.16; 'blocks': 0.16; 'combinations': 0.16; 'grp': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'flags': 0.31; 'piece': 0.31; 'thanks!': 0.32; 'run': 0.32; 'skip:_ 10': 0.34; 'but': 0.35; 'subject:?': 0.36; 'should': 0.36; 'list': 0.37; 'ahead': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'read': 0.60; 'completed': 0.61; 'first': 0.61; 'complete': 0.62; 'different': 0.65; 'yes': 0.68; 'containing': 0.69; 'florian': 0.84; 'regexp': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Florian Lindner <mailinglists@xgm.de>
Subject Why is regexp not working?
Date Fri, 04 Jul 2014 14:27:12 +0200
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host lapsgs09.informatik.uni-stuttgart.de
User-Agent KNode/4.13.2
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.11488.1404476856.18130.python-list@python.org> (permalink)
Lines 61
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404476856 news.xs4all.nl 2969 [2001:888:2000:d::a6]:60943
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73952

Show key headers only | View raw


Hello,

I have that piece of code:

    def _split_block(self, block):
        cre = [re.compile(r, flags = re.MULTILINE) for r in self.regexps]
        block = "".join(block)
        print(block)
        print("-------------------")
        for regexp in cre:
            match = regexp.match(block)
            for grp in regexp.groupindex:
                data = match.group(grp) if match else None
                self.data[grp].append(data)


block is a list of strings, terminated by \n. self.regexps:


self.regexps = [r"it (?P<coupling_iterations>\d+) .* dt complete yes | 
write-iteration-checkpoint |",
                r"it (?P<it_read_ahead>\d+) read ahead"


If I run my program it looks like that:


it 1 ahadf dt complete yes | write-iteration-checkpoint |
Timestep completed

-------------------
it 1 read ahead
it 2 ahgsaf dt complete yes | write-iteration-checkpoint |
Timestep completed

-------------------
it 4 read ahead
it 3 dfdsag dt complete yes | write-iteration-checkpoint |
Timestep completed

-------------------
it 9 read ahead
it 4 dsfdd dt complete yes | write-iteration-checkpoint |
Timestep completed

-------------------
it 16 read ahead
-------------------
{'it_read_ahead': [None, '1', '4', '9', '16'], 'coupling_iterations': ['1', 
None, None, None, None]}

it_read_ahead is always matched when it should (all blocks but the first). 
But why is the regexp containing coupling_iterations only matched in the 
first block?

I tried different combinations using re.match vs. re.search and with or 
without re.MULTILINE.

Thanks!
Florian

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


Thread

Why is regexp not working? Florian Lindner <mailinglists@xgm.de> - 2014-07-04 14:27 +0200
  Re: Why is regexp not working? Denis McMahon <denismfmcmahon@gmail.com> - 2014-07-06 02:58 +0000

csiph-web