stripping a string

Tim Rowe tim at remove_if_not_spam.digitig.co.uk
Mon Sep 15 07:26:18 EDT 2003


On Sat, 13 Sep 2003 16:15:06 -0600, Bob Gailer <bgailer at alum.rpi.edu>
wrote:

>import re
>result = re.findall(r'(\D*)\d*',  source)[0]
>
>will remove any number of trailing digits.

That might give problems if the string could also contain embedded
digits, for example "ANL1 LN32" -- it will truncate at the first
digit.  Spot on if it's what Mark wants, of course, but Jeff's
solution gives what I thought he wanted.

Funny how often when people can't work out how to do something it
turns out that what they want to do isn't precisely specified, isn't
it? :-)




More information about the Python-list mailing list