[issue36397] re.split() incorrectly splitting on zero-width pattern

Matthew Barnett report at bugs.python.org
Sat Mar 23 18:13:44 EDT 2019


Matthew Barnett <python at mrabarnett.plus.com> added the comment:

The list alternates between substrings (s, between the splits) and captures (c):

['1', '1', '2', '2', '11']
 -s-  -c-  -s-  -c-  -s--

You can use slicing to extract the substrings:

>>> re.split(r'(?<=(\d))(?!\1)(?=\d)', '12111')[ : : 2]
['1', '2', '111']

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36397>
_______________________________________


More information about the Python-bugs-list mailing list