Converting DD MM YYYY into YYYY-MM-DD?
Gilles Ganault
nospam at nospam.com
Tue Aug 18 05:07:21 EDT 2009
On Tue, 18 Aug 2009 10:52:41 +0200, Gilles Ganault <nospam at nospam.com>
wrote:
>I find it odd that the regex library can't handle European characters
>:-/
Ha, found it! :-)
http://www.regular-expressions.info/python.html
=========
# -*- coding: latin-1 -*-
import locale
import re
locale.setlocale(locale.LC_ALL, 'FR')
re_inscription =
re.compile(r"(?P<date>\d+)\s+(?P<month>\w+)\s+(?P<year>\d+)",re.LOCALE)
dateinscription = "11 Août 2008"
m = re_inscription.search(dateinscription)
if m:
day = m.group("date")
month = m.group("month")
year = m.group("year")
print "%s-%s-%s" % (year,month,day)
else:
print "Yuck"
=========
Thanks everyone!
More information about the Python-list
mailing list