您在一条评论中提到,您将字符串设置为Sun Tan SpecialistFEFFBFFECDOutfitDFBECFECAFEAFADont get burned
从本质上说,你的目标是删除任何没有紧跟着小写字母的大写字母,因为大写-小写表示短语的开头。可以使用for循环来执行此操作。在import re
h = "Sun Tan SpecialistFEFFBFFECDOutfitDFBECFECAFEAFADont get burned"
output = ""
for i in range(0, len(h)):
# Keep spaces
if h[i] is " ":
output += h[i]
# Start of a phrase found, so separate with space and store character
elif h[i].isupper() and h[i+1].islower():
output += " " + h[i]
# We want all lowercase characters
elif h[i].islower():
output += h[i]
# [1:] because we appended a space to the start of every word
print output[1:]
# If you dont care about Outfit since it is always there, remove it
print output[1:].replace("Outfit", "")
输出:
晒黑专家装不要烫伤
晒黑专家不要烫伤