我想要实现的是这样的:
>>> camel_case_split("CamelCaseXYZ")
['Camel', 'Case', 'XYZ']
>>> camel_case_split("XYZCamelCase")
['XYZ', 'Camel', 'Case']
Run Code Online (Sandbox Code Playgroud)
所以我搜索并找到了这个完美的正则表达式:
(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])
Run Code Online (Sandbox Code Playgroud)
作为我尝试的下一个逻辑步骤:
>>> re.split("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])", "CamelCaseXYZ")
['CamelCaseXYZ']
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用,如何从python中的链接问题获得结果?
编辑:解决方案摘要
我用一些测试用例测试了所有提供的解决方案:
string: ''
AplusKminus: ['']
casimir_et_hippolyte: []
two_hundred_success: []
kalefranz: string index out of range # with modification: either [] or ['']
string: ' '
AplusKminus: [' ']
casimir_et_hippolyte: []
two_hundred_success: [' ']
kalefranz: [' ']
string: 'lower'
all algorithms: ['lower']
string: 'UPPER'
all algorithms: ['UPPER']
string: 'Initial'
all algorithms: ['Initial']
string: 'dromedaryCase'
AplusKminus: ['dromedary', 'Case']
casimir_et_hippolyte: ['dromedary', …
Run Code Online (Sandbox Code Playgroud) 假设我有以下字符串:
getPasswordLastChangedDatetime
Run Code Online (Sandbox Code Playgroud)
我怎么能用大写字母拆分它以便我能得到:
get
Password
Last
Changed
Datetime
Run Code Online (Sandbox Code Playgroud)