你的问题没有很好地解决。
你对规则的描述是In other words if it is one word seperated by a space then split it
from the next word, if it is in parentheses then split the whole group
of words in the parentheses and remove them. Same goes for the commas.
我猜你用逗号是指反逗号==引号。
然后用这个strs = "Hello (Test1 test2) (Hello1 hello2) other_stuff"
你应该明白["Hello (Test1 test2) (Hello1 hello2) other_stuff"]
因为所有的东西都被反逗号包围。最有可能的是,您不需要关心最大的倒逗号。
我提议这样,尽管一个丑陋的机器人import re, itertools
strs = raw_input("enter a string list ")
print [ y for y in list(itertools.chain(*[re.split(r'\"(.*)\"', x)
for x in re.split(r'\((.*)\)', strs)]))
if y <> '']
获取>>>
enter a string list here there (x y ) thereagain "there there"
['here there ', 'x y ', ' thereagain ', 'there there']