With the re module, it seems that I am unable to split on pattern matches that are empty strings:
>>> re.split(r'(?<!foo)(?=bar)', 'foobarbarbazbar')
['foobarbarbazbar']
In other words, even if a match is found, if it's the empty string, even re.split cannot split the string.
The docs for re.split seem to support my results.
A "workaround" was easy enough to find for this particular case:
>>> re.sub(r'(?<!foo)(?=bar)', 'qux', 'foobarbarbazbar').split('qux')
['foobar', 'barbaz', 'bar']
But this is an error-prone way of doing it because then I have to beware of strings that already contain the substring that I'm splitting on:
>>> re.sub(r'(?<!foo)(?=bar)', 'qux', 'foobarbarquxbar').split('qux')
['foobar', 'bar', '', 'bar']
Is there any better way to split on an empty pattern match with the re module? Additionally, why does re.split not allow me to do this in the first place? I know it's possible with other split algorithms that work with regex; for example, I am able to do this with JavaScript's built-in String.prototype.split().