Reputation: 1
I have a python string which looks like this :
str='(/|\\)cmd\.exe$'
Now I want to remove the special characters and get string in following for,at:
new_str=replace_func(str)
print new_str
cmd.exe
Can someone help me , how to write this replace_func function. Thanks in advance!
Upvotes: 0
Views: 2348
Reputation: 41
Use regex you can remove special characters
Here is a regex to match a string of characters that are not a letters or numbers:
[^A-Za-z0-9]+
ex:
import re
str='(/|\\)cmd\.exe$'
re.sub('[^A-Za-z0-9.]+', '',str)
Upvotes: 1
Reputation: 1609
try this:
string = "(/|\\)cmd\.exe$"
chars_to_remove = ("(|\\/$")
for char in chars_to_remove:
string=string.replace(char, "")
print string
Upvotes: 0