I have a messy list of strings (list_strings), where I am able to remove using regex the unwanted characters, but I am struggling to also remove the closing bracket ] . How can I also remove those ? I guess I am very close...
#the list to clean
list_strings = ['[ABC1: text1]', '[[DC: this is a text]]', '[ABC-O: potatoes]', '[[C-DF: hello]]']
#remove from [ up to :
for string in list_strings:
cleaned = re.sub(r'[\[A-Z\d\-]+:\s*', '', string)
print(cleaned)
# current output
>>>text1]
>>>this is a text]]
>>>potatoes]
>>>hello]
Desired output:
text1
this is a text
potatoes
hello