import re
s='PageMetadataServiceConsumer, PowerSellerUpdateConsumerApplication, MetaDataDomain'
reg=r'[A-Z](?![a-z]*\b)[a-z]+'
a=re.sub(reg,'\g<0> ',s)
print(a)
OUTPUT
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
沒有爲您的解決方案的工作? –