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']
You have to allow one or more split characters:
>>> re.split('[,\s]+', "a1 a2 a3, a4,a5")
['a1', 'a2', 'a3', 'a4', 'a5']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With