There's got to be an easy way to do this

David Lees DavidLNoSpamm at raqia.com
Thu Jul 5 13:45:07 EDT 2001


How about using a regular expression with a backreference to pickout the
phone number?  Take a look at the 're' module documentation and also the
how-to.

david lees


Lindstrom Greg - glinds wrote:
> 
> I am reading in a phone number field and would like to throw away everything
> except the digits.  Being an old C programmer, I know how I would do this.
> Even with my limited knowledge of Python, I know how I would do it:
> 
>         stripped_phone=''
>         for c in phone_number:
>                 if c in digits:
>                         stripped_phone += c
> 
> but with all of the data structure support native to Python, I'm sure there
> is "an obvious way" to do it (perhaps it's because I'm not Dutch:-).
> 
> Greg Lindstrom
> Acxiom Corporation,                    mail: CWY10011149
> InfoBase Products Development                  office: (501) 342-1626
> 301 Industrial Blvd, Conway, AR, 72032     fax:     (501) 336-3911
> email: Greg.Lindstrom at acxiom.com
> 
> "When the solution is simple, God has spoken"
> 
>                                                             Albert Einstein



More information about the Python-list mailing list