re.split and lookaheads
John Machin
sjmachin at lexicon.net
Wed Mar 27 07:23:18 EST 2002
Morus Walter <morus.walter at web.de> wrote in message news:<pan.2002.03.26.21.18.19.527560.1295 at web.de>...
> Hi,
>
> I'm trying to split a string into two parts using zero width record
> boundaries.
> This should be possible by using a regular expression which consists of a
> lookahead only. Unfortunately python does not split my string.
[snip]
> If I use the same RE for searching, it matches as exepted:
This is the case with *any* zero-width pattern (as at version 2.2) --
see examples below. You should raise a documentation enhancement
request.
>>> re.split(r"\b", "abc def ghi")
['abc def ghi']
>>> re.split(r"", "abc def ghi")
['abc def ghi']
>>> re.split(r"x*", "abc def ghi")
['abc def ghi']
>>> re.sub(r"\b", "z", "abc def ghi")
'zabcz zdefz zghiz'
>>> re.sub(r"", "z", "abc def ghi")
'zazbzcz zdzezfz zgzhziz'
>>> re.sub(r"x*", "z", "abc def ghi")
'zazbzcz zdzezfz zgzhziz'
>>>
More information about the Python-list
mailing list