how to split this kind of text into sections

oyster lepto.python at gmail.com
Fri Apr 25 09:07:53 EDT 2014


I have a long text, which should be splitted into some sections, where
all sections have a pattern like following with different KEY. And the /n/r
can not be used to split

I don't know whether this can be done easily, for example by using RE module

[demo text starts]
a line we do not need
I am section axax
I am section bbb, we can find that the first 2 lines of this section all
startswith 'I am section'
.....(and here goes many other text)...
let's continue to
 let's continue, yeah
 .....(and here goes many other text)...
I am using python
I am using perl
 .....(and here goes many other text)...
[demo text ends]

the above text should be splitted as a LIST with 3 items, and I also need
to know the KEY for LIST is ['I am section', 'let's continue', 'I am
using']:
lst=[
 '''I am section axax
I am section bbb, we can find that the first 2 lines of this section all
startswith 'I am section'
.....(and here goes many other text)...''',

'''let's continue to
 let's continue, yeah
 .....(and here goes many other text)...''',


'''I am using python
I am using perl
 .....(and here goes many other text)...'''
]

I hope I have state myself clear.

Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140425/513c393d/attachment.html>


More information about the Python-list mailing list