I've been trying to remove the numberings from the following lines using a Python script.
jokes.txt:
It’s hard to explain puns to kleptomaniacs because they always take things literally.
I used to think the brain was the most important organ. Then I thought, look what’s telling me that.
When I run this Python script:
import re
with open('jokes.txt', 'r+') as original_file:
modfile = original_file.read()
modfile = re.sub("\d+\. ", "", modfile)
original_file.write(modfile)
The numbers are still there and it gets appended like this:
It’s hard to explain puns to kleptomaniacs because they always take things literally.
I used to think the brain was the most important organ. Then I thought, look what’s telling me that.1. It’s hard to explain puns to kleptomaniacs because they always take things literally.ഀഀ2. I used to think the brain was the most important organ. Then I thought, look what’s telling me that.
I guess the regular expression re.sub("\d+\. ", "", modfile)finds all the digits from 0-9 and replaces it with an empty string.
As a novice, I'm not sure where I messed up. I'd like to know why this happens and how to fix it.