making a valid file name...

Fredrik Lundh fredrik at
Wed Oct 18 13:24:23 CEST 2006

Matthew Warren wrote:

>>> import re
>>> badfilename='£"%^"£^"£$^ihgeroighroeig3645^£$^"knovin98u4#346#1461461'
>>> valid=':./,^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '
>>> goodfilename=re.sub('[^'+valid+']',' ',badfilename)

to create arbitrary character sets, it's usually best to run the character string through
re.escape() before passing it to the RE engine.


More information about the Python-list mailing list