Splitting text at whitespace but keeping the whitespace in the returned list

python at bdurham.com python at bdurham.com
Sun Jan 24 18:36:33 CET 2010


"MRAB" <python at mrabarnett.plus.com> wrote:
> >>> import re
> >>> re.split(r'(\s+)', "Hello world!")
> ['Hello', ' ', 'world!']

That was exactly (EXACTLY!) the solution I was looking for.

Thank you!

More information about the Python-list mailing list