What's wrong with the phone number?<br><br>>>> phoneNumber.search(line).groups()<br>('03', '88', '23', '05', '66')<br><br>This looks fine to me.<br><br>Here is a regex that splits the line into several named groups. Test it with other strings, though<br>
<br>>>> line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23 05 66 <a href="mailto:strasbourg@artisansdumonde.org">strasbourg@artisansdumonde.org</a>"<br><br>>>> details_re = re.compile(r'(?P<region>^\D+)(?P<postcode>\d+)\s+(?P<town>[\D\s]+)(?P<address>.+?)(?P<phone>\d{2} \d{2} \d{2} \d{2} \d{2})\s+(?P<email>[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4})')<br>
<br>>>> m = details_re.search(line)<br><br>>>> print m.groups()<br>('ALSACE ', '67000', 'Strasbourg ', '24 rue de la Division Leclerc ', '03 88 23 05 66', '<a href="mailto:strasbourg@artisansdumonde.org">strasbourg@artisansdumonde.org</a>')<br>
<br>>>> print m.group('phone')<br>03 88 23 05 66<br><br>>>> print m.group('email')<br><a href="mailto:strasbourg@artisansdumonde.org">strasbourg@artisansdumonde.org</a><br><br><br>Emmanuel<br>
<br><br><div class="gmail_quote">On Thu, Dec 31, 2009 at 2:49 PM, Norman Khine <span dir="ltr"><<a href="mailto:norman@khine.net">norman@khine.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
hello,<br>
<br>
>>> import re<br>
>>> line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23 05 66 <a href="mailto:strasbourg@artisansdumonde.org">strasbourg@artisansdumonde.org</a>"<br>
>>> m = re.search('[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}', line)<br>
>>> emailAddress .search(r"(\d+)", line)<br>
>>> phoneNumber = re.compile(r'(\d{2}) (\d{2}) (\d{2}) (\d{2}) (\d{2})')<br>
>>> phoneNumber.search(line)<br>
<br>
but this jumbles the phone number and also includes the 67000.<br>
<br>
how can i split the 'line' into a list?<br>
<br>
thanks<br>
norman<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br>
<br>
</blockquote></div><br>