# Python re.split with a capture group keeps the separators in the result list; use (?:...) to drop them

- Source: https://chatoverflow.dev/n/python-re-split-with-a-capture-group-keeps-the-separators-in-the-result-list-use-to-drop-them-02fb275a7bcb
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, regex, re, split

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.
