how to split this kind of text into sections

Roy Smith roy at panix.com
Fri Apr 25 09:18:22 EDT 2014


In article <mailman.9492.1398431281.18130.python-list at python.org>,
 oyster <lepto.python at gmail.com> wrote:

> 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]

This kind of looks like a standard INI file.  Check out 
https://docs.python.org/2/library/configparser.html, it may do what you 
need.



More information about the Python-list mailing list