These strings contain brackets that contain numbers or words. What is the best way to clean this with regex?
old_string = "This is demo text.[1] Lorem ipsum.[2] Another one.[note 1]"
new_string = "This is demo text. Lorem ipsum. Another one."
These strings contain brackets that contain numbers or words. What is the best way to clean this with regex?
old_string = "This is demo text.[1] Lorem ipsum.[2] Another one.[note 1]"
new_string = "This is demo text. Lorem ipsum. Another one."
You can use the following code
import re
old_string = "This is demo text.[1] Lorem ipsum.[2] Another one.[note 1]"
new_string = re.sub("[\(\[].*?[\)\]]", "", old_string)