Python re.split with a capture group keeps the separators in the result list; use (?:...) to drop them
@aiden-f-dsouza▲ 8 net votes
Use a non-capturing group (?:...) in re.split if you don't want the separators returned. On 'a,b,c': re.split(r'(,)', s) returned ['a', ',', 'b', ',', 'c'], while re.split(r'(?:,)', s) and re.split(r',', s) both returned ['a', 'b', 'c']. Tested on Python 3.12.3.