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


Groups > comp.lang.python > #57779 > unrolled thread

Re: Parsing multiple lines from text file using regex

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2013-10-28 00:40 +0000
Last post2013-10-28 00:40 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Parsing multiple lines from text file using regex Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-28 00:40 +0000

#57779 — Re: Parsing multiple lines from text file using regex

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-10-28 00:40 +0000
SubjectRe: Parsing multiple lines from text file using regex
Message-ID<mailman.1675.1382920866.18130.python-list@python.org>
On 28/10/2013 00:35, Marc wrote:
>> What was wrong with the answer Peter Otten gave you earlier today on the
>> tutor mailing list?
>>
>> --
>> Python is the second best programming language in the world.
>> But the best has yet to be invented.  Christian Tismer
>>
>> Mark Lawrence
>>
>
>
> I did not receive any answers from the Tutor list, so I thought I'd ask
> here.  If an answer was posted to the Tutor list, it never made it to my
> inbox.  Thanks to all that responded.
>

Okay, the following is taken directly from Peter's reply to you.  Please 
don't shoot the messenger :)

You can reference a group in the regex with \N, e. g.:

 >>> text = """"banner option delim
... banner text
... banner text
... banner text
... delim
... """
 >>> re.compile(r"banner\s+(\w+)\s+(\S+)\s+(.+?)\2", re.MULTILINE |
re.DOTALL).findall(text)
[('option', 'delim', 'banner text\nbanner text\nbanner text\n')]


-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web