【发布时间】:2018-11-22 14:17:04
【问题描述】:
我有很多字符串需要用逗号分隔。示例:
myString = r'test,Test,NEAR(this,that,DISTANCE=4),test again,"another test"'
myString = r'test,Test,FOLLOWEDBY(this,that,DISTANCE=4),test again,"another test"'
我想要的输出是:
["test", "Test", "NEAR(this,that,DISTANCE=4)", "test again", """another test"""] #list length = 5
我不知道如何在一项中保留“this,that,DISTANCE”之间的逗号。我试过这个:
l = re.compile(r',').split(myString) # matches all commas
l = re.compile(r'(?<!\(),(?=\))').split(myString) # (negative lookback/lookforward) - no matches at all
有什么想法吗?假设允许的“函数”列表定义为:
f = ["NEAR","FOLLOWEDBY","AND","OR","MAX"]
【问题讨论】: