Joshua Joshua - 6 months ago 23
Python Question

python substring with unknown symbol

I have a string that I need to edit in python. Lets say the string is: thisandthat+this. The string could be any length.

Now pretend you don't know what/where in the string the special characters are. For example these characters: +-)(&^%$#@!*

How do I grab everything except for the special characters? So for the above example my result would be thisandthatthis.


If space is not included in special, you can use

''.join(re.split("[^a-z]", input_str))

You can also use re.sub

re.sub("[^a-z]", "", input_str)