I am trying to convert camel case to space separated values using python. For example:
divLineColor -> div Line Color
This lin
This should work with 'divLineColor', 'simpleBigURL', 'OldHTMLFile' and 'SQLServer'.
label = re.sub(r'((?<=[a-z])[A-Z]|(?
Explanation:
label = re.sub(r"""
( # start the group
# alternative 1
(?<=[a-z]) # current position is preceded by a lower char
# (positive lookbehind: does not consume any char)
[A-Z] # an upper char
#
| # or
# alternative 2
(?
If a match is found it is replaced with ' \1', which is a string consisting of a leading blank and the match itself.
Alternative 1 for a match is an upper character, but only if it is preceded by a lower character. We want to translate abYZ to ab YZ and not to ab Y Z.
Alternative 2 for a match is an upper character, but only if it is followed by a lower character and not at the start of the string. We want to translate ABCyz to AB Cyz and not to A B Cyz.