Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73952 > unrolled thread
| Started by | Florian Lindner <mailinglists@xgm.de> |
|---|---|
| First post | 2014-07-04 14:27 +0200 |
| Last post | 2014-07-06 02:58 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | Florian Lindner <mailinglists@xgm.de> |
|---|---|
| Date | 2014-07-04 14:27 +0200 |
| Subject | Why is regexp not working? |
| Message-ID | <mailman.11488.1404476856.18130.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-07-06 02:58 +0000 |
| Message-ID | <lpadvq$6rc$6@dont-email.me> |
| In reply to | #73952 |
On Fri, 04 Jul 2014 14:27:12 +0200, Florian Lindner wrote: > self.regexps = [r"it (?P<coupling_iterations>\d+) .* dt complete yes | > write-iteration-checkpoint |", > r"it (?P<it_read_ahead>\d+) read ahead" My first thought is what is the effect of '|' as the last character in the regex? -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web