A problem with re.split()

Hrvoje Niksic hniksic at srce.hr
Wed Jun 2 15:49:41 CEST 1999


I understand that the idea with "re" module is for it to behave as
closely to Perl's regular expressions as possible (which is why the
order of arguments in string.split and re.split is different,
string.split being the logical one).

The problem is with re.split() in this case:

$ python
Python 1.5.2 (#3, May 23 1999, 19:57:40)  [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import re
>>> re.split('', 'foo')
['foo']

Perl splits it to ['f', 'o', 'o']:

$ perl -e 'print join(":", split("", "foo"))'
f:o:o




More information about the Python-list mailing list