Replace Several Items

Eric Wertman ewertman at gmail.com
Wed Aug 13 13:42:24 EDT 2008


I tend to use the re module like so :

import re
my_string = re.sub('[\-,./]','',my_string)

> I wish to replace several characters in my string to only one.
> Example, "-", "." and "/" to nothing ""
> I did like that:
> my_string = my_string.replace("-", "").replace(".", "").replace("/",
> "").replace(")", "").replace("(", "")
>
> But I think it's a ugly way.
>
> What's the better way to do it?



More information about the Python-list mailing list