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
  • 739
  • 2
  • 7
  • 30

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
  • 42,087
  • 4
  • 55
  • 81