I have a variable named para and I want to remove all the non-alphabet characters excluding whitespace characters. For the following input:
para = "I a, going #?5 1throu$gh Lots Of ]pain
kcb H in"
required output
para = "I a going through Lots Of pain
kcb H in"
Code Tried
import re
regex = re.compile('[^a-zA-Z]')
regex.sub('', para)
Output getting
'IagoingthroughLotsOfpain'
>Solution :
import re
regex = re.compile('[^a-zA-Z\s]')
regex.sub('', para)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ]). See regex101.com.