phone number regex

Andrew Dalke dalke at acm.org
Sat Aug 26 19:23:03 EDT 2000


I admit to not really understanding your question.  You want to
reformat the text, but do you want to delete the phone or the city
name?  Are there other lines in the data file you need to ignore?

Tony Johnson wrote in message <39A7E3CF.1B135E93 at gs.verio.net>...
>This should be fairly easy but just wanted to ask.  I have an isp phone
>list file with lines formatted as such
>
>State City 555-555-555
>
>I need to reformat the file.  I am trying to make a regex that will
>match the phone number field.

You're coming from Perl, aren't you?  There are other functions
which may be more useful, and faster.  How about (untested):

import string
s="State City 555-555-5555"
fields = string.split(s)
city = string.join(fields[:-1])
phone = fields[-1:]

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list