fork download
  1. import re
  2.  
  3. test_text = ['Sentence 1 (Author, 2019).',
  4. 'Sentence 2 (Another Author, 2020)',
  5. 'Sentence 3 (First Author & Second Author, 2018)',
  6. 'Sentence 4 (Author, 2019; Another Author, 2020; Fourth Author, 2017)']
  7.  
  8. test_list = []
  9. pattern = r'\(([^()]+)\)'
  10.  
  11. for elem in test_text:
  12. temp = []
  13. for splitOne in re.search(pattern, elem).group(1).split(";"):
  14. for splitTwo in splitOne.split(":"):
  15. temp.append(splitTwo.strip())
  16. test_list.append(temp)
  17.  
  18. print("FULL LIST OF PULL:\n", test_list)
Success #stdin #stdout 0.02s 9508KB
stdin
Standard input is empty
stdout
FULL LIST OF PULL:
 [['Author, 2019'], ['Another Author, 2020'], ['First Author & Second Author, 2018'], ['Author, 2019', 'Another Author, 2020', 'Fourth Author, 2017']]