【问题标题】:Splitting a string based on commas but keeping relevant ones根据逗号拆分字符串但保留相关的
【发布时间】:2022-09-29 22:05:05
【问题描述】:

我想根据逗号进行拆分,但想保留其中包含相关逗号的句子。该字符串在字符串之间没有任何类型的双引号。 例如:

string = \'The Three Musketeers, are, Athos, Porthos and Aramis\'

输出:

str_to_list = [\'The Three Musketeers\', \'are\', \'Athos, Porthos and Aramis\']

    标签: python regex python-re


    【解决方案1】:

    尝试这个

    string = 'The Three Musketeers, are, Athos, Porthos and Aramis'
    string.split(',')
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 2010-11-05
      相关资源
      最近更新 更多