beginners question about return value of re.split

klaus kla at us.de
Fri Mar 21 11:19:05 EDT 2008


Hello,

I have a question regarding the return value of re.split() since I have 
been unable to find any answers in the regular sources of documentation.

Please consider the following:

#!/usr/bin/env python

import re

if __name__ == "__main__":
    datum = "2008-03-14"
    the_date = re.split('^([0-9]{4})-([0-9]{2})-([0-9]{2})$', datum, 3)
    print the_date

Now the result that is printed is:
['', '2008', '03', '14', '']

My question: what are the empty strings doing there in the beginning and 
in the end ? Is this due to a faulty regular expression ?

Thank you !

KL.



More information about the Python-list mailing list