file1.txt
contains:
Thailand,[a] officially the Kingdom of Thailand and formerly known as Siam,[b] is a country in Southeast Asia.
I want to delete the words between []
and ()
. The expected output is:
Thailand, officially the Kingdom of Thailand and formerly known as Siam, is a country in Southeast Asia.
This is my code:
with open('file1.txt') as file1:
file1 = file1.read()
test = re.sub(r'[\(\[].*[\)\]]', '', file1)
My code deletes all the words between [a]
and [b]
. The example output:
Thailand is a country in Southeast Asia.