re.split() not keeping matched text

Robert Oschler no_replies at fake_email_address.invalid
Sun Jul 25 21:25:29 CEST 2004


Hello,

Given the following program:

--------------

import re

x = "The dog ran. The cat eats! The bird flies? Done."
l = re.split("[.?!]", x)

for s in l:
  print s.strip()
# for
---------------

I am getting the following output:

The dog ran
The cat eats
The bird flies
Done

As you can see the end of sentence punctuation marks are being removed.  Yet
the the docs for re.split() say that the matched text is supposed to be
returned.  I want to keep the punctuation marks.

Where am I going wrong here?

Thanks,
-- 
Robert





More information about the Python-list mailing list