string.rstrip

Alan Kennedy alanmk at hotmail.com
Wed Sep 24 06:38:28 EDT 2003


Matthew Wilson wrote:
> What would be the best way to strip off the last "_asdf" from
> "asdf_asdf_asdf"?

I don't about "the best way" (define "best"), but here's another way

#--------------
import re
patt = re.compile('_asdf$')
mystring = "asdf_asdf_asdf"
print patt.sub('', mystring)
#--------------------------

HTH,

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list