假設您有一個字符串(例如聖誕禮物列表)。re.findall - 從逗號分隔的字符串獲取項目列表
presents = 'iPods, Windows 8, .hack//Sign boxset , red shoes , Wall-E DVD, Deus Ex: Human Revolution '
逗號分隔的項目都是任意的,可以包含數字,標點符號或特殊字符(逗號除外)。我想用Python獲取這些項目的數組。
presents_arr = ['iPods', 'Windows 8', '.hack//Sign boxset', 'red shoes', 'Wall-E DVD', 'Deus Ex: Human Revolution']
我通常會用逗號分隔符來分割字符串,然後用split來清理每個字符串。
presents = presents.split(',')
presents = [present.strip() for present in presents]
的我們的好奇心,我能和re.findall做專?我需要與split/strip相同的行爲。