Reputation: 1
I have been looking around for a while to any kind of solution to my problem the only thing close is how to replace a specific line if i know the non ASCII string already but what i would like to do is a loop for every line in a txt file to find every single non ASCII string and replace it with just the word STRING
variable Name ‘ƒ variable2 Name2 ƒŠ‡
I have only found people removing all ascii and filling the blanks in between.
Upvotes: 0
Views: 103
Reputation: 661
Try the Python standard library re.sub
:
import re
txt = "‘ƒ variable2 Name2 ƒŠ‡"
txt = re.sub(r"[^\x1F-\x7F]+", "STRING", txt)
print(txt)
Then use this method for each line in your file.
Upvotes: 3