Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python / Remove special character from string

Tags:

python

I'm writing server side in python.

I noticed that the client sent me one of the parameter like this:

"↵                        tryit1.tar↵                        "

I want to get rid of spaces (and for that I use the replace command), but I also want to get rid of the special character: "↵".

How can I get rid of this character (and other weird characters, which are not -,_,*,.) using python command?

like image 815
Or Smith Avatar asked Sep 23 '14 09:09

Or Smith


1 Answers

A regex would be good here:

re.sub('[^a-zA-Z0-9-_*.]', '', my_string)
like image 102
Daniel Roseman Avatar answered Oct 24 '22 22:10

Daniel Roseman