fork download
  1. import re
  2. list_strings = ['[ABC1: text1]', '[[DC: this is a text]]', '[ABC-O: potatoes]', '[[C-DF: hello]]']
  3.  
  4. #remove from [ up to :
  5. for string in list_strings:
  6. m = re.search(r'\[+[A-Z\d-]+:\s*(.*?)\s*]', string)
  7. if m:
  8. print(m.group(1))
  9.  
  10. # All matches
  11. matches = re.findall(r'\[+[A-Z\d-]+:\s*(.*?)\s*]', string)
  12. print(matches)
Success #stdin #stdout 0.03s 9432KB
stdin
Standard input is empty
stdout
text1
['text1']
this is a text
['this is a text']
potatoes
['potatoes']
hello
['hello']