re.split and lookaheads
Morus Walter
morus.walter at web.de
Tue Mar 26 15:18:19 EST 2002
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.
So for example:
import re
text = "abc"
exp = re.compile("(?=b)")
print exp.split(text)
prints
['abc']
whereas I would expect ['a', 'bc'].
(since (?=b) is supposed to match the position before b)
Is this a limitation of pythons re split? Or am I missing something?
If I use the same RE for searching, it matches as exepted:
e.g.
mo = exp.search(text)
print mo.start(), mo.end()
=> 1 1
I know, that I can get the record boundaries as part of the result list,
if the RE matches some text, but that's not really what I want to get.
Any comments?
greetings
Morus
More information about the Python-list
mailing list