我想使用python re.split()以逗号将一个句子分割成多个字符串,但我不想将其应用于用逗号分隔的单个单词,例如:重新分割特殊情况以分割逗号分隔的字符串
例
s = "Yes, alcohol can have a place in a healthy diet."
desired result = ["Yes, alcohol can have a place in a healthy diet."]
另一个例子:
s = "But, of course, excess alcohol is terribly harmful to health in a variety of ways, and even moderatealcohol intake is associated with an increase in the number two cause of premature death: cancer."
desired output = ["But, of course" , "excess alcohol is terribly harmful to health in a variety of ways" , "and even moderatealcohol intake is associated with an increase in the number two cause of premature death: cancer."]
任何指针?请。
你尝试过这么远吗? – depperm
也许你应该在逗号分割,然后重新组合单个单词与下一个短语。另外,如果有多个这样的词“嘿,嘿,嘿,当然,是......”? –
@depperm,我试过像sep = re.split('(?<!\ d)[,](?!\ d)',string)和其他没有人似乎是防弹的 –