[Tutor] matching a street address with regular expressions

Christopher Spears cspears2002 at yahoo.com
Thu Oct 4 04:29:13 CEST 2007


One of the exercises in Core Python Programming is to
create a regular expression that will match a street
address.  Here is one of my attempts.

>>> street =  "1180 Bordeaux Drive"
>>> patt = "\d+ \w+"
>>> import re
>>> m = re.match(patt, street)
>>> if m is not None: m.group()
...
'1180 Bordeaux'
>>>

Obviously, I can just create a pattern "\d+ \w+ \w+". 
However, the pattern would be useless if I had a
street name like 3120 De la Cruz Boulevard.  Any
hints?



More information about the Tutor mailing list