Split a string at uppercase letters

Unfortunately it’s not possible to split on a zero-width match in Python. But you can use re.findall instead:

>>> import re
>>> re.findall('[A-Z][^A-Z]*', "https://stackoverflow.com/questions/2277352/TheLongAndWindingRoad")
['The', 'Long', 'And', 'Winding', 'Road']
>>> re.findall('[A-Z][^A-Z]*', 'ABC')
['A', 'B', 'C']

Leave a Comment