import re regex = r"\(([^()/]+(?:/[^()/]+)*)\)" test_str = "stuff (word1/Word2/w0rd3) stuff, stuff (word4/word5) stuff stuff (word6) stuff (word7/word8/word9) stuff stuff, (w0rd10/word11) stuff stuff (word12) stuff (Word13/w0rd14/word15) stuff-stuff stuff (word16/word17)." res = list(map(lambda x: x.split('/'), re.findall(regex, test_str))) print(res)
Standard input is empty
[['word1', 'Word2', 'w0rd3'], ['word4', 'word5'], ['word6'], ['word7', 'word8', 'word9'], ['w0rd10', 'word11'], ['word12'], ['Word13', 'w0rd14', 'word15'], ['word16', 'word17']]