0

I have a code:

import re
print(re.split(' (\d+)','APPLE JUICE 20'))

Why am I getting an empty string at the end of the list and how to fix that?

['APPLE JUICE', '20', '']
Igor Dragushhak
  • 567
  • 1
  • 3
  • 14
  • The match is at the end of the string, so you have an empty item in the result. [*If there are capturing groups in the separator and it matches at the start of the string, the result will start with an empty string. The same holds for the end of the string*](https://docs.python.org/3/library/re.html) – Wiktor Stribiżew Feb 08 '19 at 10:09
  • It's just how it works. Similarly if you split `a,` by `,`, you will get an empty string at the end. – Jerry Feb 08 '19 at 10:10
  • print(re.split('(\d+)','APPLE JUICE 20')[:-1]) – LemonPy Feb 08 '19 at 10:13

0 Answers0