re.split() not keeping matched text

Test usenet at diefenba.ch
Sun Jul 25 15:44:21 EDT 2004


Hi Robert, 

Robert Oschler wrote:

> l = re.split("[.?!]", x)

> I want to keep the punctuation marks.
 
The docs say: If _capturing parentheses_ are used in pattern, then the text
of all groups in the pattern are also returned as part of the resulting
list.

So: 

l = re.split("([.?!])", x)

will work as wanted. 

Bye, 
Kai 



More information about the Python-list mailing list