I have tried one regex but that removes all the contents inside the brackets but i want that content.
Sentence: "Narendra Modi <N-Modi> is PM of India"
Output that i want : "Narendra Modi N-Modi is PM of India"
Code tried:
import re
#Replace all white-space characters with the digit "9":
txt = "Narendra Modi <N-Modi> is PM of India"
x = re.sub("\<[^\]]*\>", "", txt)
print(x)
>Solution :
I did not understand what you wanted, but if you have
"Narendra Modi is PM of India"
and you want output to be: "Narendra Modi N-Modi is PM of India"
hence replacing all angular brackets….
str = "Narendra Modi <N-Modi> is PM of India"
output = re.sub("[<>]", "", str)
print(output)
should do the work.