On 10/4/07, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Christopher Spears wrote: > > 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? > > >
Also, that pattern can be easily modified to have any number of words at the end: patt = "\d+ (\w+){1,}" This would take care of 3120 De la Cruz Boulevard. -- http://mail.python.org/mailman/listinfo/python-list