re.split() not keeping matched text

Robert Oschler no_replies at fake_email_address.invalid
Sun Jul 25 22:07:51 CEST 2004


"Test" <usenet at diefenba.ch> wrote in message
news:ce12hh$vc9$06$1 at news.t-online.com...
> Hi Robert,
>
> 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

Kai,

That works.  Unfortunately the punctuation marks (matched text) are returned
as separate list entries.  Is there any way to avoid having to walk the list
by steps of 2, and rejoin the "n" and "n+1" elements, to get back the
original sentence(s)?  I'm trying to save some processing time if possible.

Thanks,
-- 
Robert





More information about the Python-list mailing list