Splitting on '^' ?

Gabriel gabriel at opensuse.org
Fri Aug 14 22:41:36 CEST 2009


On Fri, Aug 14, 2009 at 5:23 PM, kj<no.email at please.post> wrote:
>
>>>> import re
>>>> re.split('^', 'spam\nham\neggs\n')
> ['spam\nham\neggs\n']
>>>> re.split('(?m)^', 'spam\nham\neggs\n')
> ['spam\nham\neggs\n']
>>>> bol_re = re.compile('^', re.M)
>>>> bol_re.split('spam\nham\neggs\n')
> ['spam\nham\neggs\n']
>
> Am I doing something wrong?
>

Maybe this:

>>> import re
>>> te = 'spam\nham\neggs\n'
>>> pat = '\n'
>>> re.split(pat,te)
['spam', 'ham', 'eggs', '']

-- 
Kind Regards



More information about the Python-list mailing list