Scott SA wrote: > There are a lot of cool things you can do with regex, one of them in > relation to your needs, is the ability to replace substrings: > > >>> import re > >>> reg = re.compile('(.exe)$') # the $ means end of line > >>> reg.sub('','123.exe') > '123'
Unfortunately there are also many opportunities for subtle errors: >>> re.compile("(.exe)$").sub("", "abcexe") 'ab' >>> re.compile(r"(\.exe)$").sub("", "abcexe") 'abcexe' >>> re.compile(r"(\.exe)$").sub("", "abc.exe") 'abc' A dot normally matches any character except newline, so you have to escape it. Peter -- http://mail.python.org/mailman/listinfo/python-list