Python: convert camel case to space delimited using RegEx and taking Acronyms into account

后端 未结 10 1901
逝去的感伤
逝去的感伤 2020-12-29 04:38

I am trying to convert camel case to space separated values using python. For example:

divLineColor -> div Line Color

This lin

10条回答
  •  天涯浪人
    2020-12-29 05:17

    \g<0> references the matched string of the whole pattern while \g<1> refereces the matched string of the first subpattern ((…)). So you should use \g<1> and \g<2> instead:

    label = re.sub("([a-z])([A-Z])","\g<1> \g<2>",label)
    

提交回复
热议问题