我想在大/小写的边界分割下面的字符串。我如何在Python和/或正则表达式中执行此操作?
例如,
x = 'aagaaggagatataccATGAATTTGTCGGTTTACCCCAATTTAACCAAAgaaaacctgtacaa'
split_boundaries(x) = ['aagaaggagatatacc',
'ATGAATTTGTCGGTTTACCCCAATTTAACCAAA',
'gaaaacctgtacaa']
答案 0 :(得分:4)
使用re.findall
:
import re
x = 'aagaaggagatataccATGAATTTGTCGGTTTACCCCAATTTAACCAAAgaaaacctgtacaa'
re.findall(r'[a-z]+|[A-Z]+', x)
# ['aagaaggagatatacc', 'ATGAATTTGTCGGTTTACCCCAATTTAACCAAA', 'gaaaacctgtacaa']