Splitting on a regex w/o consuming delimiter
Terry Reedy
tjreedy at home.com
Sun Nov 11 02:16:41 EST 2001
"Lars Kellogg-Stedman" <lars at larsshack.org> wrote in message
news:slrn9us6kv.3id.lars at flowers.house.larsshack.org...
> Given a string such as:
>
> sample = 'one two @three @four five @six'
>
> I want to split it on the '@' character, but I want the '@'
character to be
> retained in each sequence. That is, I'd like the above string split
into:
>
> one two
> @three
> @four five
> @six
You could do '@'.split(sample)' (which deletes at) and then add back
to all but first.
Terry J. Reedy
More information about the Python-list
mailing list