I want my code to only return the special characters [".", "*", "=", ","]
I want to remove all digits/alphabetical characters ("\W")
and all white spaces ("\S")
import re
original_string = "John is happy. He owns 3*4=12, apples"
new_string = re.findall("\W\S",original_string)
print(new_string)
But instead I get this as my output:
[' i', ' h', ' H', ' o', ' 3', '*4', '=1', ' a']
I have absolutely no idea why this happens. Hence I have two questions:
1) Is it possible to achieve my goal using regular expressions
2) What is actually going on with my code?