How to keep the special alphabet/character in a text file using Python?
Input text file:
abcÃ/cdéf@-www
I want to remove the symbol, but keep alphabet and special alphabet, symbol means ~!@#$%^*()_+{}<>:"|
and so on. After I tried to run my code to do so, here is what I got:
Output text file:
abc cd f www
The symbols have been removed and replaced with space which is what I want, but the special alphabets have been removed and replaced with space as well which I don't want. Is there any way to remove symbols but keep special alphabets only?
Expected output text file:
abcà cdéf www
Here is my code:
string = open('abc.txt', encoding='utf-8').read()
new_str = re.sub('[^a-zA-Z0-9\n\.]', ' ', string)
open('abc.txt', 'w', encoding='utf-8').write(new_str)