may be a bug in string.rstrip
Peter Otten
__peter__ at web.de
Fri Nov 23 04:14:30 EST 2007
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
More information about the Python-list
mailing list