Regex Question
Thomas Güttler
guettler at thomas-guettler.de
Thu Aug 21 06:17:01 EDT 2003
Istvan Albert wrote:
> Thomas Güttler wrote:
>> Hi!
>>
>> I want to parse a file that looks like this:
>>
>> a0001: basbasdb
>> asbddsb
>> asdbasdb
>> abasbd
>> a0002: fffff
>> ffff
>> ffffff
>> ffff
>
>> I think there is a better solution than this, don't you?
> It is not clear from what you are saying what are the limitations
> for possible key and values. If the ":" character cannot appear
> in a key or a value you could do something a lot simpler:
>
> elems = line.split(":")
Thank you for this reply. With re.split() it is the way I like it:
regex=re.compile(r'((?:^|\n)\w\d*:)')
splits=regex.split(content)
thomas
More information about the Python-list
mailing list