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

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


I need to parse some ASCII text into 'word' sized chunks of text
AND collect the whitespace that seperates the split items. By
'word' I mean any string of characters seperated by whitespace
(newlines, carriage returns, tabs, spaces, soft-spaces, etc).
This means that my split text can contain punctuation and numbers
- just not whitespace.

The split( None ) method works fine for returning the word sized
chunks of text, but destroys the whitespace separators that I
need.

Is there a variation of split() that returns delimiters as well
as tokens?

Thank you,
Malcolm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100124/b8c744bb/attachment.html>


More information about the Python-list mailing list