[Tutor] using re to match text and extract info

Norman Khine norman at khine.net
Thu Dec 31 14:49:10 CET 2009


hello,

>>> import re
>>> line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23 05 66 strasbourg at artisansdumonde.org"
>>> m = re.search('[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}', line)
>>> emailAddress .search(r"(\d+)", line)
>>> phoneNumber = re.compile(r'(\d{2}) (\d{2}) (\d{2}) (\d{2}) (\d{2})')
>>> phoneNumber.search(line)

but this jumbles the phone number and also includes the 67000.

how can i split the 'line' into a list?

thanks
norman


More information about the Tutor mailing list