re.split and lookaheads

Morus Walter morus.walter at web.de
Fri Mar 29 03:00:45 EST 2002


On Wed, 27 Mar 2002 13:23:18 +0100, John Machin wrote:

> This is the case with *any* zero-width pattern (as at version 2.2) --
> see examples below. 

Thanks for your answer.
I understand now, what's going on.

> You should raise a documentation enhancement request.
> 

Though I understand that pythons behaviour can be considered reasonable in
the cases you list, I definitly prefer perls semantik, as using such RE makes
a lot of sense to me in the case of lookaheads or lookbehinds.
So a feature request might be more, what I want.
But I'm not sure, whether that would be welcome, since it might break
code.
Fortunately one can easily write one's own split function, to avoid the
problem.

>>>> re.sub(r"\b", "z", "abc def ghi")
> 'zabcz zdefz zghiz'
Hmm. 
So re.sub accepts zero width matches? Strange.

greetings
	Morus



More information about the Python-list mailing list