Using re.findall
:
>>> import re
>>> ex = 'OCaOSeOO'
>>> re.findall('[A-Z][a-z]?', ex)
['O', 'Ca', 'O', 'Se', 'O', 'O']
Regex explanation:
[A-Z]
: Match uppercase letter
[a-z]
: Match lowercase letter
[A-Z][a-z]
: Match uppercase letter followed by lowercase letter
[A-Z][a-z]?
: Match uppercase letter followed by 0 or 1 lowercase letters
[A-Z][a-z]*
: Match uppercase letter followed by 0 or more lowercase letters. (* is greedy, it will match as many as found)
>>> import re
>>> ex = 'OCaOSeOO'
>>> re.findall('[A-Z]', ex)
['O', 'C', 'O', 'S', 'O', 'O']
>>> re.findall('[A-Z][a-z]', ex)
['Ca', 'Se']
>>> re.findall('[A-Z][a-z]?', ex)
['O', 'Ca', 'O', 'Se', 'O', 'O']
>>>
Edit #1: For another example mentioned in the comments:
>>> ex = 'ABbCccDdddEeeeeFfffffGggggggg'
>>> re.findall('[A-Z][a-z]*', ex)
['A', 'Bb', 'Ccc', 'Dddd', 'Eeeee', 'Ffffff', 'Gggggggg']