<分区>
尝试让 re.split 正常工作。 输入 = "a1 a2 a3, a4,a5"
expecting output = ['a1','a2','a3','a4','a5']
s = re.split(',|\s', "a1 a2 a3, a4,a5")
getting output = ['a1','a2','a3',' ','a4','a5']
<分区>
尝试让 re.split 正常工作。 输入 = "a1 a2 a3, a4,a5"
expecting output = ['a1','a2','a3','a4','a5']
s = re.split(',|\s', "a1 a2 a3, a4,a5")
getting output = ['a1','a2','a3',' ','a4','a5']
最佳答案
您必须允许一个或多个拆分字符:
>>> re.split('[,\s]+', "a1 a2 a3, a4,a5")
['a1', 'a2', 'a3', 'a4', 'a5']
关于Python re.split on ","或 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53269725/