6

Trying to get re.split to work correctly. Input = "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']
Borisw37
  • 511
  • 2
  • 5
  • 22

1 Answers1

8

You have to allow one or more split characters:

>>> re.split('[,\s]+', "a1 a2 a3, a4,a5")
['a1', 'a2', 'a3', 'a4', 'a5']
Daniel
  • 39,063
  • 4
  • 50
  • 76