I would like to break up a string into those parts starting with a capital letter using regular expressions. But I get an error in Python v3.6 if I try it with the expression I thought would work.
import re
str = "abcDefgHijkLmnoPQrstUvwxYz"
pattern = "[A-Z]"
print (re.split(pattern, str) # will provide ['abc,'efg','ijk', ...] but want the caps
pattern = r"([A-Z])"
print (re.split(pattern, str) # will provide ['abc, 'D','efg','H', 'ijk', ...]
pattern = r"(?=[A-Z])" # thought this one would include the capitals with the lower case
print (re.split(pattern, str) # generates an error - "requires a non-empty pattern"
# expected this to provide ['abc', 'Defg', 'Hijk', 'Lmno', ...
# also thought that str.split(pattern) would work the same was as re.split but it does not. Why isn;t .split() consistent with re.split()?
What would be the proper regex that would provide words starting with capital letters?