I have a string like this: ape4banana3
and I split it like this:
>>>re.split('([1-5]?)|\s', "ape4banana3")
['ape', '4', 'banana', '3', '']
Why do I get the trailing ''
in my result? Can I get rid of it by writing a smarter regex?
Side note: The regex has the alternation because sometimes the string looks like this: ape4 banana3
and then I want to lose the whitespace.
For extra credit: Is there a way I can get this result instead? ['ape4', 'banana3']
?