I am not sure where the small mistake is being made, but I want to remove all special characters including numbers from a text.
I used this:
def remove_special_chars(text):
""" Method to remove special characters
"""
print("original Text: {}\n".format(text))
pattern=r'[^a-zA-z.\s]'
text=re.sub(pattern,"",text)
print("Modified text: {}".format(text))
And I get this:
remove_special_chars("Hi How_abc.com_are you!. hello_123@gmail.com?_")
original Text: Hi How_abc.com_are you!. hello_123@gmail.com?_
Modified text: Hi How_abc.com_are you. hello_gmail.com_
So while everything else seems to work fine, I am not sure why _ is not getting removed when it is not there in character class?