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


Groups > comp.lang.python > #57779

Re: Parsing multiple lines from text file using regex

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Parsing multiple lines from text file using regex
Date 2013-10-28 00:40 +0000
References <002d01ced358$e18ab5f0$a4a021d0$@org> <l4k3tg$fp4$1@ger.gmane.org> <005401ced375$8ee093c0$aca1bb40$@org>
Newsgroups comp.lang.python
Message-ID <mailman.1675.1382920866.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

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

csiph-web