import re
s='PageMetadataServiceConsumer, PowerSellerUpdateConsumerApplication, MetaDataDomain'
reg=r'[A-Z](?![a-z]*\b)[a-z]+'
a=re.sub(reg,'\g<0> ',s)
print(a)
输出
Page Metadata Service Consumer, Power Seller Update Consumer Application, Meta Data Domain
说明
[A-Z] #First char with capital letter
(?! #START Negative Look ahead: Do not match if the first char is followed by this
[a-z]*\b #do not match if it ends with a word boundary \b(last part)
) #END Negative Look ahead
[a-z]+ #Select all the remaining lower case chars.
a=re.sub(reg,'\g<0> ',s) #Replace the matches with match \g<0> by appending a space to it.
工作正则表达式here。
工作python示例here。
如果您只想要单词,请使用以下内容:-
reg=r'[A-Z]+[a-z]+'
for a in re.findall(reg,s):
print(a)
输出
Page
Metadata
Service
Consumer
Power
Seller
Update
Consumer
Application
Meta
Data
Domain