Tol*_*lu 1 python string split
我怎么能分开这个?
'Symptoms may include:Absent or small knucklesCleft palateDecreased skin creases at finger jointsDeformed earsDroopy eyelidsInability to fully extend the joints from birth (contracture deformity)Narrow shouldersPale skinTriple-jointed thumbs'
Run Code Online (Sandbox Code Playgroud)
期望的输出应该采用这种形式
Symptoms may include:
Absent or small knuckles
Cleft palate
Decreased skin creases at finger joints
Deformed ears
Droopy eyelids
Inability to fully extend the joints from birth (contracture deformity)
Narrow shoulders
Pale skin
Triple-jointed thumbs
Run Code Online (Sandbox Code Playgroud)
喜欢拆分大写字母.
使用re.findall(由于@Brendan Abel和@JFF而改善了模式):
fragments = re.findall('[A-Z][^A-Z]*', text)
Run Code Online (Sandbox Code Playgroud)
print(fragments)
['Symptoms may include:',
'Absent or small knuckles',
'Cleft palate',
'Decreased skin creases at finger joints',
'Deformed ears',
'Droopy eyelids',
'Inability to fully extend the joints from birth (contracture deformity)',
'Narrow shoulders',
'Pale skin',
'Triple-jointed thumbs']
Run Code Online (Sandbox Code Playgroud)
细节
[A-Z] # match must begin with a uppercase char
[^A-Z]* # further characters in match must not contain an uppercase char
Run Code Online (Sandbox Code Playgroud)
注意:*允许您使用单个大写字符捕获句子.+如果不是所需的功能,则替换.
此外,如果您希望输出为多行字符串:
print('\n'.join(fragments))
Run Code Online (Sandbox Code Playgroud)