Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正規表現を使用して、複数の区切り記号を使用して文字列を分割しています。しかし、2 つの区切り文字が文字列内で隣り合って発生すると、結果のリストに空の文字列が配置されます。例えば:
re.split(',|;', "This,is;a,;string")
結果は
['This', 'is', 'a', '', 'string']
区切り文字として''追加せずにリストに入らないようにする方法はありますか?,;
''
,;
これを試して:
import re re.split(r'[,;]+', 'This,is;a,;string') > ['This', 'is', 'a', 'string']